zoukankan      html  css  js  c++  java
  • ECMAScript 面向对象JS学习笔记1

    1.对象的 prototype 属性,可以把它看成创建新对象所依赖的原型。===在我理解,就是prototype下设置的字段是唯一性的,共享性的,不管创建多少个对象,所处空间都是不变的,没有增加也没有减少,指向的指针都是指向那最初的地方。

    教程: http://www.w3school.com.cn/js/pro_js_object_defining.asp

     1 function Car(sColor,iDoors,iMpg) {
     2   this.color = sColor;
     3   this.doors = iDoors;
     4   this.mpg = iMpg;
     5   this.drivers = new Array("Mike","John");
     6 }
     7 
     8 Car.prototype.showColor = function() {
     9   alert(this.color);
    10 };
    11 
    12 Car.prototype.test=new Array("First","Second");
    13 
    14 var oCar1 = new Car("red",4,23);
    15 var oCar2 = new Car("blue",3,25);
    16 
    17 oCar1.drivers.push("Bill");
    18 oCar1.test.push("Third")
    19 alert(oCar1.drivers);    //输出 "Mike,John,Bill"
    20 alert(oCar2.drivers);    //输出 "Mike,John"
    21 alert(oCar1.test);    //输出 "First,Second,Third"
    22 alert(oCar2.test);    //输出 "First,Second,Third"
    原型方式

    2.看教程的时候,有typeof ,instanceof这样的方法,其中,instanceof针对的是创建的对象,而不是原有的类型。在这里能看到a的类型是number,但是如果不创建function number(){}的话,

    那么将无法输出document.write( a instanceof number)这个结果。而当创建后,则会显示false

    var a=1
    document.write( typeof  a)//number
    function number(){}
    document.write( a instanceof number)//false
    a=new number();
    document.write( a instanceof number)//true
    

     3.

     待续 》》》

  • 相关阅读:
    Javascript FP-ramdajs
    微信小程序开发
    SPA for HTML5
    One Liners to Impress Your Friends
    Sass (Syntactically Awesome StyleSheets)
    iOS App Icon Template 5.0
    React Native Life Cycle and Communication
    Meteor framework
    RESTful Mongodb
    Server-sent Events
  • 原文地址:https://www.cnblogs.com/danlis/p/6775117.html
Copyright © 2011-2022 走看看