Skip to content

Instantly share code, notes, and snippets.

@ChezCrawford
Created September 15, 2016 15:39
Show Gist options
  • Save ChezCrawford/d832b8692161d6e92d2a74beff30bf5e to your computer and use it in GitHub Desktop.
Save ChezCrawford/d832b8692161d6e92d2a74beff30bf5e to your computer and use it in GitHub Desktop.
Private Object Functions
'use strict'
let MyObject = require('./myObject');
let myObjectInstance = new MyObject('abc');
console.log(myObjectInstance.externalFunction());
'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