首页 > 代码库 > javascript构造函数模块

javascript构造函数模块

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