var Person = (function(){
var Constr;
Constr = function(){
this.name = ‘carl‘;
}
Constr.prototype = {
constructor : Constr,
getName : function(){
return this.name;
}
}
return Constr;
}())
var obj = new Person();
console.log(obj.getName()); //输出:carl
javascript构造函数模块
时间: 2024-10-12 08:00:43