3 ms·
var Person = function() { var privateMethod = function() {...}; };
by aymeric 14y ago
var Person = function() { var privateMethod = function() {...}; };
- ricardobeat 14y agowhy: what's your reasoning for using them? A more memory-efficient approach: var Person = (function(){ function Person(x){ this.x = x } function myPrivateMethod(x){ //... } Person.prototype.something = function(){ y = myPrivateMethod(this.x) } return Person })()
- swah 14y agoNormally I use code like this to avoid polluting the global namespace -- you might as well throw your functions in there and they will be "private": (function(){ })();