Skip to content

Instantly share code, notes, and snippets.

@bbatliner
Last active May 4, 2016 02:22
Show Gist options
  • Save bbatliner/ff1d00cd324d2bfa3b6aaf05235ba3f7 to your computer and use it in GitHub Desktop.
Save bbatliner/ff1d00cd324d2bfa3b6aaf05235ba3f7 to your computer and use it in GitHub Desktop.
Data privacy and extension with Javascript!
var Person = function (firstName, lastName) {
function privateGetName() {
return `${firstName} ${lastName}`;
}
return {
getName() {
return privateGetName();
},
speak() {
console.log('Hello!');
}
};
};
var SalesPerson = function (firstName, lastName) {
return Object.assign(Object.create(Person(firstName, lastName)), {
sell() {
console.log('That\'ll be $5!');
},
// Override
speak() {
Object.getPrototypeOf(this).speak.call(this);
console.log(`My name is ${this.getName()}`);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment