4 ms·
If you really need private member variables you can probably whip something up with lambdas, though it might be a little awkward.
by repsilat 15y ago
If you really need private member variables you can probably whip something up with lambdas, though it might be a little awkward.
- reissbaker 15y agoIt's super easy: function A { var secret = 0; // <---------- private variable this.method = function() { alert(secret); }; this.increment = function() { secret++; }; } a = new A(); a.increment(); a.method(); <-------- prints 1 The main problem is just the inefficiency of declaring methods inside constructors. Edit: Hence, the keyword.