2 ms·
Being able to declare member variables as private (really private, not the private alluded to in Ruby) is good. As the OP said, you don't have to declare a memb
by davedx 15y ago
Being able to declare member variables as private (really private, not the private alluded to in Ruby) is good. As the OP said, you don't have to declare a member variable as private if you want relaxed 0constraints. But when you want to for good design reasons -- it's great that the language you are working with allows you to do so.
- repsilat 15y agoIf 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.