欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 寫類方式之五

 更新時間:2009年07月05日 01:38:16   作者:  
用 構(gòu)造函數(shù)+原型 定義一個類;同一構(gòu)造函數(shù)可以定義出多個類型
5、用 構(gòu)造函數(shù)+原型 定義一個類;同一構(gòu)造函數(shù)可以定義出多個類型
復(fù)制代碼 代碼如下:

/**
* $define 寫類工具函數(shù)之二
* @param {Object} constructor
* @param {Object} prototype
*/
function $define(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
return function() {
for(var atr in p)
arguments.callee.prototype[atr] = p[atr];
c.apply(this,arguments);
}
}

與第四種方式類似,仍然用構(gòu)造函數(shù),原型對象,定義兩個類。
復(fù)制代碼 代碼如下:

//構(gòu)造函數(shù)
function Person(name) {
this.name = name;
}
//原型對象
var proto = {
getName : function(){return this.name},
setName : function(name){this.name = name;}
}
//定義兩個類
var Man = $define(Person,proto);
var Woman = $define(Person,proto);
console.log(Man == Woman);//false,同一個構(gòu)造函數(shù)(Person)定義不同的類

相關(guān)文章

最新評論