Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Base function
- function Drinks(data) {
- var that = {}; // Create an empty object
- that.name = data.name; // Add it a "name" property
- return that; // Return the object
- };
- // Fuction which inherits from the base function
- function Coffee(data) {
- // Create the Drinks object
- var that = Drinks(data);
- // Extend base object
- that.giveName = function() {
- return 'This is ' + that.name;
- };
- return that;
- };
- // Usage
- var firstCoffee = Coffee({ name: 'Cappuccino' });
- console.log(firstCoffee.giveName());
- // Output: "This is Cappuccino"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement