javascript組合使用構(gòu)造函數(shù)模式和原型模式實例
更新時間:2015年06月04日 10:55:26 作者:MaxOmnis
這篇文章主要介紹了javascript組合使用構(gòu)造函數(shù)模式和原型模式的方法,通過一個簡單實例分析了javascript構(gòu)造函數(shù)模式與原型模式的使用方法,需要的朋友可以參考下
本文實例講述了javascript組合使用構(gòu)造函數(shù)模式和原型模式的方法。分享給大家供大家參考。具體如下:
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程序設(shè)計有所幫助。
您可能感興趣的文章:
- javascript設(shè)計模式 – 原型模式原理與應用實例分析
- 深入了解js原型模式
- JavaScript創(chuàng)建對象方式總結(jié)【工廠模式、構(gòu)造函數(shù)模式、原型模式等】
- 詳解js產(chǎn)生對象的3種基本方式(工廠模式,構(gòu)造函數(shù)模式,原型模式)
- js面向?qū)ο笾R妱?chuàng)建對象的幾種方式(工廠模式、構(gòu)造函數(shù)模式、原型模式)
- javascript原型模式用法實例詳解
- 深入理解JavaScript系列(42):設(shè)計模式之原型模式詳解
- JavaScript設(shè)計模式之原型模式(Object.create與prototype)介紹
- JS面向?qū)ο蠡A(chǔ)講解(工廠模式、構(gòu)造函數(shù)模式、原型模式、混合模式、動態(tài)原型模式)
- 怎樣用JavaScript實現(xiàn)原型模式
相關(guān)文章
常用Javascript函數(shù)與原型功能收藏(必看篇)
下面小編就為大家?guī)硪黄S肑avascript函數(shù)與原型功能收藏(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10javascript實現(xiàn)的顏色塊滑動的動態(tài)效果
javascript實現(xiàn)的顏色塊滑動的動態(tài)效果...2007-08-08