Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The prototype of js and the use of Construction method

Shulou Source: shulou.com Published: 2022-06-02 20:14:04 09月25日 Update

The difference between classes and objects

Class: mold

Object: product (finished product)

For example:

Var arr1=new Array (12, 10, 11, 112, 111, 52)

Array: class

Arr1: object

Can only arr1.push (), not Array.push ()

Use constructor to add attributes, prototype add method

Function createPerson (name,qq) / / constructor

{

/ / after the new is created, the system automatically declares:

/ / var this=new Object ()

This.name=name

This.qq=qq

/ / return obj

/ / the system will automatically return:

/ / return this

}

Var obj=new createPerson ('Zhan Shaonan', '265404540')

Var obj2=new createPerson ('Esteban', '112233')

CreatePerson.prototype.showName=function () / / prototype

{

Alert ('my name is:'+ this.name)

}

CreatePerson.prototype.showqq=function ()

{

Alert ('my QQ is:'+ this.qq)

}

Obj.showName ()

Obj.showqq ()

Obj2.showName ()

Obj2.showqq ()

Tags: Object prototype function system method product name young man attribute finished product mold Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Huawei Docker vpn