Last active
May 4, 2016 02:22
-
-
Save bbatliner/ff1d00cd324d2bfa3b6aaf05235ba3f7 to your computer and use it in GitHub Desktop.
Data privacy and extension with Javascript!
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
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