Created
September 15, 2016 15:39
-
-
Save ChezCrawford/d832b8692161d6e92d2a74beff30bf5e to your computer and use it in GitHub Desktop.
Private Object Functions
This file contains 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
'use strict' | |
let MyObject = require('./myObject'); | |
let myObjectInstance = new MyObject('abc'); | |
console.log(myObjectInstance.externalFunction()); |
This file contains 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
'use strict' | |
const MyObject = function MyObject(specialValue) { | |
this.objectSpecificValue = specialValue; | |
}; | |
const privateFunction = function privateFunction() { | |
// Why can we not properly access "this" since privateFunction would always be called from child objects? | |
console.log('inside the privateFunction: ', this.objectSpecificValue); | |
return this.objectSpecificValue; | |
}; | |
MyObject.prototype.externalFunction = function() { | |
return privateFunction(); | |
}; | |
module.exports = MyObject; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment