ECMAScript Object-oriented JS Learning Note 1

Source: Internet
Author: User

1. The prototype property of an object can be seen as a prototype on which to create a new object. = = = In my understanding, that is, the field set under prototype is unique, shared, no matter how many objects are created, the space is constant, there is no increase or decrease, pointing pointers are pointing to the original place.

Tutorial: http://www.w3school.com.cn/js/pro_js_object_defining.asp

1 functionCar (scolor,idoors,impg) {2    This. color =Scolor;3    This. Doors =idoors;4    This. mpg =Impg;5    This. Drivers =NewArray ("Mike", "John");6 }7 8Car.prototype.showColor =function() {9Alert This. color);Ten }; One  Acar.prototype.test=NewArray ("First", "Second"); -  - varOCAR1 =NewCar ("Red", 4,23); the varOCAR2 =NewCar ("Blue", 3,25); -  -OCar1.drivers.push ("Bill"); -OCar1.test.push ("Third") +alert (ocar1.drivers);//output "Mike,john,bill" -alert (ocar2.drivers);//output "Mike,john" +alert (ocar1.test);//output "First,second,third" Aalert (ocar2.test);//output "First,second,third"
prototype Mode

2. Look at the tutorial, there are typeof, instanceof such methods, wherein, instanceof for the creation of the object, rather than the original type. Here you can see that the type of a is number, but if you do not create a function number () {},

Then the result of document.write (a instanceof number) cannot be output. And when it is created, false is displayed

var a=1document.write (typeof  a)//numberfunction number () {}document.write (a instanceof number)//falsea=new Number ();d ocument.write (a instanceof number)//true

3.

(continued) "

ECMAScript Object-oriented JS Learning Note 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.