Why javascript function has instance per call?
问题 The javascript introduction says: When I have code like below: var Person=function(name){ this.name=name; this.sayHello=function(){return 'Hello '+name;} } Whenever I instantiate a "Person", there will be a copy of "sayHello" function in the memory. To reduce this memory consumption, I can change the code like below: var Person=(function(){ var sayHello=function(){return 'Hello '+name} return function(name){ this.name=name this.sayHello=sayHello } })() In this way, there'll not be multiple