Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Javascript closures providing private methods and variables.

View public private javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
var object = function() {
var _privateVariable = 0;
 
function _privateFunction() {
alert('i am in a closure');
}
function _privateFunctionTwo() {
alert('nothing outside the object created by this function can reach me.');
_privateFunction();
}
return {
publicFunction : function() {
alert('everything can reach me, and i can call private functions in this closure...');
_privateFunctionTwo();
_privateVariable++;
},
publicProperty : 'i am public property'
};
}();
View public private javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var object = function() {
function privateFunction() {
alert('i am in a closure');
}
function privateFunctionTwo() {
alert('nothing outside the object created by this function can reach me.');
}
return {
publicFunction : function() {
alert('everything can reach me');
},
publicProperty : 'i am public property'
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.