Created
August 4, 2016 09:06
-
-
Save maxleiko/aa46f357075fcc0f19ffd2562ec5b098 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyType = require('./MyType.js'); | |
const t = new MyType(); | |
t.id = 42; | |
t.publicMethod(); | |
t.publicMethodThatCallsPrivate('hello', 'world'); | |
t.privateMethod(); // won't work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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