Is there anyway to have instances share the same function yet at the same time have private variables?
问题 I have this piece of code: var Human=function(name){ this._name=name; }; Human.prototype.Shout=function(){ alert(this._name); }; var tom=new Human("tom"); var john=new Human("john"); alert(tom.Shout===john.Shout); Right now ._name is not "private". I want to make ._name "private", but at the same time i do not wish to create additional functions for each instance of Human (in other words tom.Shout Must be === to john.Shout) because creating additional functions for each instance is just well.