如何获取一个构造函数从Javascript中的构造函数继承? [英] How to get a constructor function to inherit from a constructor function in Javascript?
本文介绍了如何获取一个构造函数从Javascript中的构造函数继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在学习Javascript及其所有的原型善良,我对以下情况感到厌烦:
So I'm learning Javascript and all its' prototype goodness, and I am stumped over the following:
说我有这个
var Animal = function (a, b, c, d, e, f, g, h, i, j, k , l, m, n){
this.a = a;
this.b = b;
//...etc...
};
var x = new Animal(1,2,3....);
现在我如何创建一个Cat构造函数,它继承自Animal构造函数,不得不再次键入超长参数?
Now how do I create a Cat constructor function that inherits from the Animal constructor function such that I don't have to type the super long arguments again?
换句话说,我不想这样做:
In other words I don't want to be doing this:
var Cat = function (a, b, c, d, e, f, g, h, i, j, k , l, m, n){
this.a = a;
this.b = b;
//...etc...
};
// inherit functions if any
Cat.prototype = new Animal;
var y = new Cat(1,2,3....);
提前感谢!
j
Thanks in advance! j
推荐答案
如何?
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....);
这篇关于如何获取一个构造函数从Javascript中的构造函数继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文