Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Maria Dan
Added: May 19, 2021 4:43 PM
Modified: May 19, 2021 4:45 PM
Views: 436
Tags: no tags
  1. const Animal = function (name, type) {
  2.   this.name = name
  3.   this.type = type
  4.   this.action = function() {
  5.     alert('base action')
  6.   }
  7. }
  8.  
  9. const Cat = function() {
  10.   Animal.apply(this, arguments)
  11.   this.breed = 'cat'
  12. }
  13.  
  14. Cat.prototype = Object.create(Animal.prototype)
  15. Cat.prototype.constructor = Cat
  16.  
  17. const cat = new Cat ('name1', 'cat', 2, 3);
  18. console.log(cat.type)
  19.