Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The prototype of js and the use of Construction method

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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 ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report