日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > web前端 > jscript > Javascript中定義類(class)的幾種方法總結(jié)

Javascript中定義類(class)的幾種方法總結(jié)

來源:程序員人生   發(fā)布時間:2013-11-28 12:37:39 閱讀次數(shù):3308次
方法一:工廠方式--- 創(chuàng)建并返回特定類型的對象的 工廠函數(shù) ( factory function )
function createCar(color,doors,mpg){
var tempCar = new Object;
tempCar.color = color;
tempCar.doors = doors;
tempCar.mpg = mpg;
tempCar.showCar = function(){
alert(this.color + " " + this.doors);
}
return tempCar;
}
方法二:構(gòu)造函數(shù)方式--- 構(gòu)造函數(shù)看起來很像工廠函數(shù)
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.showCar = function(){
alert(this.color);
};
}
方法三:原型方式--- 利用了對象的 prototype 屬性,可把它看成創(chuàng)建新對象所依賴的原型
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.drivers = new Array("nomad","angel");
}
Car.prototype.showCar3 = function(){
alert(this.color);
};
方法四:混合的構(gòu)造函數(shù) /原型方式--- 用構(gòu)造函數(shù)定義對象的所有非函數(shù)屬性,用原型方式定義對象的函數(shù)屬性(方法)
function Car(sColor, iDoors, iMpg) {
this.color = sColor;
this.doors = iDoors;
this.mpg = iMpg;
this.drivers = new Array("Mike", "Sue");
}
Car.prototype.showColor = function () {
alert(this.color);
};
方法五:動態(tài)原型方法--- 在構(gòu)造函數(shù)內(nèi)定義非函數(shù)屬性,而函數(shù)屬性則利用原型屬性定義。唯一的區(qū)別是賦予對象方法的位置。
function Car(sColor, iDoors, iMpg) {
this.color = sColor;
this.doors = iDoors;
this.mpg = iMpg;
this.drivers = new Array("Mike", "Sue");
if (typeof Car._initialized == "undefined") {

Car.prototype.showColor = function () {
alert(this.color);
};

Car._initialized = true;
}
}
//該方法使用標(biāo)志( _initialized )來判斷是否已給原型賦予了任何方法。
利用原型prototype。 function Bar(text, url) {
this.text = text;
this.url = url;
}
Bar.prototype = {
render : function() {
document.write('<a href="' + this.url + '">' + this.text + '</a>');
}
}
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 视频一区亚洲 | 午夜欧美一区二区三区在线播放 | 噜噜色av| 欧美精品一区在线观看 | 91精品啪在线观看国产线免费 | 国产成人在线视频 | 男女羞羞免费视频 | 日韩精品一区二区三区四区 | 亚洲一区av在线 | 国产成人精品综合 | 天堂精品一区二区三区 | 精品视频在线看 | 一本亚洲 | 99re视频| 日本精品中文字幕 | av片在线看 | 国产高清中文字幕 | 国产一区二区精品在线 | 国产99视频精品免视看9 | 欧洲亚洲女同hd | 欧美在线视频一区二区 | 色av吧| 永久免费在线观看 | 久热这里只有精品6 | 亚洲网站在线播放 | av一区在线 | 国产乱码精品一区二区三区不卡 | 久久成人一区二区 | 国产精品18hdxxxⅹ在线 | 搞黄视频在线免费观看 | 亚洲欧美国产另类 | 久久久久在线观看 | 综合婷婷 | 日朝毛片| 欧美成人精品一区二区 | 黄色片a级片 | 国产精品综合久久 | 91久久精品国产91久久 | 成人久久影院 | 又湿又紧又大又爽a视频国产 | 希岛爱理和黑人中文字幕系列 |