3 ms·
It's super easy: function A { var secret = 0; // <---------- private variable this.method = function() { alert(secret); }; this.increme
by reissbaker 15y ago
It'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.