首页 > 技术文章 > javascript构造函数模块

fengzekun 2014-08-05 15:59 原文

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

推荐阅读