Skip to content

@schell /public private javascript
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Javascript closures providing private methods and variables.
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'
};
}();
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.