Skip to content

Instantly share code, notes, and snippets.

@davidrhyswhite
Created March 25, 2016 16:32
Show Gist options
  • Save davidrhyswhite/f8ed7a561d9fc37dee08 to your computer and use it in GitHub Desktop.
Save davidrhyswhite/f8ed7a561d9fc37dee08 to your computer and use it in GitHub Desktop.
var Service = (function () {
var Service = function () {
this.say = "Hello";
}
Service.prototype.publicMethod = function () {
privateMethod.call(this);
}
var privateMethod = function () {
console.log(this.say);
}
return Service;
})();
// Uncaught TypeError: (intermediate value).privateMethod is not a function(...)
new Service().privateMethod();
// Will successfully call privateMethod internally.
new Service().publicMethod();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment