想用js的繼承優(yōu)化一段代碼,但是發(fā)現(xiàn),參數(shù)使用對象格式的,就不行。我可不想在構(gòu)造函數(shù)中按順序來寫參數(shù)。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;}這個怎么破?
js如何實現(xiàn)對象參數(shù)格式的繼承?
哆啦的時光機
2019-04-09 20:25:15