Skip to content

Instantly share code, notes, and snippets.

@asciidisco
Created September 10, 2012 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asciidisco/3692732 to your computer and use it in GitHub Desktop.
Save asciidisco/3692732 to your computer and use it in GitHub Desktop.
"Privates" in JS
// Defining "private" properties in JavaScript
// define youre own scope by using an
// immediate executed function
(function (){
// x is only be visible within this scope a.k.a this function
var x = null;
var Bla = function(blup) {
// x is visible here
   x = blup;
};
Bla.prototype.on = function() {
// x is visible here
       alert(x);
};
}());
// x is not visible here
console.log(typeof x === 'undefined'); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment