(function(){ var name = ""; Person = function(value){ name = value; }; Person.prototype.getName = function(){ return name; }; Person.prototype.setName = function(value){ name = value; } })(); var person1 = new Person("Ming"); console.log(person1.getName());