3 ms·
why private methods?
by ricardobeat 14y ago
why private methods?
- aymeric 14y agovar 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(){ })();