星空网 > 软件开发 > Java

创建对象的最好方式_最好的继承机制(代码实例)

      /* 创建对象的最好方式:混合的构造函数/原型方式,       *用构造函数定义对象的所有非函数属性,用原型方式定义对象的函数属性(方法)       */      function People(sname){        this.name = sname;      }      People.prototype.sayName = function(){        console.log(this.name);      }      /* 最好的继承机制:       * 用对象冒充继承构造函数的属性,用原型prototype继承对象的方法。       */      function Student(sname,sage){        People.call(this,sname);        this.age = sage;      }      Student.prototype = new People();      Student.prototype.sayAge = function(){        console.log(this.age);      };      //实例      var people1 = new People("jeff");      people1.sayName(); //输出:jeff      var student1 = new Student("john",30);      student1.sayName(); //输出:john
       student1.sayAge(); //输出:30




原标题:创建对象的最好方式_最好的继承机制(代码实例)

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Lazada GST:https://www.goluckyvip.com/tag/8206.html
越南tiktok下载:https://www.goluckyvip.com/tag/82060.html
tiktok免登陆国内直接看:https://www.goluckyvip.com/tag/82061.html
tiktok热点宝:https://www.goluckyvip.com/tag/82062.html
国际版tiktok官网中文:https://www.goluckyvip.com/tag/82064.html
tiktok突然没有流量了:https://www.goluckyvip.com/tag/82065.html
石象湖景区门票-石象湖景区门票优惠政策:https://www.vstour.cn/a/411243.html
北京到嵩山自驾游沿途景点 北京距离嵩山有多远:https://www.vstour.cn/a/411244.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流