想用js的继承优化一段代码,但是发现,参数使用对象格式的,就不行。我可不想在构造函数中按顺序来写参数。varP=function(opts){this.name=opts.name;this.age=opts.age;};P.prototype={constructor:P,getName:function(){returnthis.name;},getAge:function(){returnthis.age;}};varS=function(opts){P.call(this,opts);this.address=opts.address;};S.prototype=newP();S.prototype.constructor=S;S.prototype.getAddress=function(){returnthis.address;}这个怎么破?
相关分类