How to get a constructor function to inherit from a constructor function in Javascript?

后端 未结 2 1867
难免孤独
难免孤独 2021-01-12 09:14

So I\'m learning Javascript and all its\' prototype goodness, and I am stumped over the following:

Say I have this

var Animal = function (a, b, c, d,         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-12 09:42

    How's this?

    var Cat = Function (a, b, c, d, e, f, g, h, i, j, k , l, m, n){
       Animal.apply(this, arguments);
    };
    
    // inherit functions if any
    Cat.prototype = new Animal;
    
    var y = new Cat(1,2,3....);
    

提交回复
热议问题