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.

     待续 》》》

  • 相关阅读:
    utf8编码和中文不能解码问题解决
    python环境的安装配置
    repo同一个仓的同一个changeId的提交
    Jenkins pipeline之将命令的运行结果赋值给变量
    repo和git常用的命令和场景
    docker 安装rabbitmq
    docker的一些概念
    mysql数据库sql优化原则
    数据库优化02
    MySQL数据库优化总结
  • 原文地址:https://www.cnblogs.com/danlis/p/6775117.html
Copyright © 2011-2022 走看看