Skip to content

Instantly share code, notes, and snippets.

@maxleiko
Created August 4, 2016 09:06
Show Gist options
  • Save maxleiko/aa46f357075fcc0f19ffd2562ec5b098 to your computer and use it in GitHub Desktop.
Save maxleiko/aa46f357075fcc0f19ffd2562ec5b098 to your computer and use it in GitHub Desktop.
const MyType = require('./MyType.js');
const t = new MyType();
t.id = 42;
t.publicMethod();
t.publicMethodThatCallsPrivate('hello', 'world');
t.privateMethod(); // won't work
function MyType() {
this.id = null;
}
function privateMethod(foo, bar) {
console.log('private work on instance: ' + this.id);
console.log(foo, bar);
}
MyType.prototype.publicMethod = function () {
console.log('public work on instance: ' + this.id);
};
MyType.prototype.publicMethodThatCallsPrivate = function () {
console.log('gonna call private: ' + this.id);
privateMethod.apply(this, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment