Last active
December 25, 2015 02:58
-
-
Save nherment/6905953 to your computer and use it in GitHub Desktop.
private scope vs prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FooPublic() { | |
this._publicVariable; | |
} | |
FooPublic.prototype.increment = function() { | |
return ++ this._publicVariable; | |
} | |
var f = new FooPublic(); | |
f.increment(); // nice | |
f._publicVariable --; // now, I'm messing with the internals | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FooPrivate() { | |
var privateVariable = 0; | |
this.increment = function() { | |
return ++privateVariable; | |
} | |
} | |
var f = new FooPrivate(); | |
f.increment(); // nice | |
f.privateVariable --; // f does not have member 'privateVariable' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment