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