Skip to content

Instantly share code, notes, and snippets.

@tmccombs
Created November 2, 2013 15:57
Show Gist options
  • Save tmccombs/7280357 to your computer and use it in GitHub Desktop.
Save tmccombs/7280357 to your computer and use it in GitHub Desktop.
A method to create a truly private method in Javascript
var MyClass;
function() {
MyClass = function() {
this.prop = {};
}
//private method
function getProp() {
return this.prop;
}
//public method
MyClass.prototype.foo = function() {
return "foo " + getProp.call(this); //how to call the private method.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment