javascript组合使用构造函数模式和原型模式实例

网络编程 发布日期:2024/10/6 浏览次数:1

正在浏览:javascript组合使用构造函数模式和原型模式实例

本文实例讲述了javascript组合使用构造函数模式和原型模式的方法。分享给大家供大家参考。具体如下:

function testPrototype2(){
  function Person3(name, age, job){
    this.name=name;
    this.age=age;
    this.job=job;
    this.friends =["shelb", "court"];
  }
  Person3.prototype = {
    constructor:Person3,
    sayName:function(){
      alert(this.name);
    }
  }
  var person1 = new Person3("jack",10,"it");
  var person2 = new Person3("karry",1,"woker");
  person1.friends.push("tom");
  console.info(person1.friends);
  console.info(person2.friends);
  console.info(person1.friends==person2.friends);
  console.info(person1.sayName == person2.sayName);
}

希望本文所述对大家的javascript程序设计有所帮助。

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。