Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Base function
  2. function Drinks(data) {
  3.   var that = {}; // Create an empty object
  4.   that.name = data.name; // Add it a "name" property
  5.   return that; // Return the object
  6. };
  7.  
  8. // Fuction which inherits from the base function
  9. function Coffee(data) {
  10.   // Create the Drinks object
  11.   var that = Drinks(data);
  12.   // Extend base object
  13.   that.giveName = function() {
  14.     return 'This is ' + that.name;
  15.   };
  16.   return that;
  17. };
  18.  
  19. // Usage
  20. var firstCoffee = Coffee({ name: 'Cappuccino' });
  21. console.log(firstCoffee.giveName());
  22. // Output: "This is Cappuccino"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement