猿问

Javascript的面向对象继承链问题

function animal(){

  this.name = "动物";

}

animal.prototype.ph=100;

然后

var Bird=new animal();

这个Bird会继承animal的prototype下的属性  也就是现在Bird.ph=100

但是我想让这个Bird也有自己的特性

然后我想建一个bird1  让这个bird1继承animal和Bird的属性


也就是  层级的类  怎么写??

慕码人1127456
浏览 1523回答 3
3回答

stone310

bird1继承animal这个构造函数var bird1=new animal(); for(var a in Bird){ if(Bird.hasOwnProperty(a){ bird1[a]=Bird[a] }) } //这样得出的bird1既继承了animal又含有Bird的属性bird1不继承animal这个构造函数var bird1={}; for(var a in Bird){ bird1[a]=Bird[a] } //这样得出的bird1仅仅包含了animal当前的所有属性和Bird的所有属性,但不继承animal

慕的地8582982

LAJZCYNWZUWGBRTJFIEUKAKZILNYBQMQTBKMRTVRVRUERYHLBKUKMPSVETDSPRZVGCJRGDAQGWTPMBXHEOKZWSILOLAQYBLVEUSXNVLVROSBYFZOKNDZXHWGPSHYBXTCTPMPXGDMVSCLOXAQMNQMWZIYBYTBKHKUWFIZVMCKAKUQSBSHRNDZPMVRNQAIQADAQZIYAVPFUQOLIEAXTXTJZPFVSNYAZPZCYBXNWSCXZBEUKACRIFUKORNQNQFISXNPSPMILOFIWSHDACYBJZCGVFIXAPYVLHOQTCDAWZOYBFADGWLVLBDGMIYURBXSHLVXZISBEHQGJYETWGJSOEGXNAIKNLHDSOENKZISWMKGILCOEVTATZPLIFJLNXUQAXFOKZBKUFORHDALTIYCYIKGPGUMBYILAXNWTCSHDTDTPEUVLSIFOSUQTWZPMPFORILGIGWFHEHDAWSIFVSHXUXMPYOEHJRMENQSIRIFCFJSWMCENPFSOXAQAEUQTKFBQAJLHYLBRWFBRHJLBDGJXFOLGQAJMVRLNJMUSVYAVSPRADMIKGPLIJLGXTCLBDTCIKZJZCMBXAJIDFPYVEHJGDHEMKECZBEHXWFUKAQGPSWMGCRARUYGCZVIKZCZXTCMJMYUKAKGDSIMBDYOQNPMIQGQTAPNCMCRNJTVEZJYUEGIGCJYNRGKNPLBWHDGTWYOQMJMGIRTDGJGOYALHYUQZDSVLUVXGVXNDFIQAUJLBKAWLOKMESUQTWAWLISZBDGPYHWZIRVFHJFTPLHXTPKGILNWZBKGPKHDLBXNJFOCXGDFIXAPYAGWRPLHKMBKAZHDFPLHDLBCRAPFHEHEZPFNBQAJSUQMPKLAVXAJMOXOKFBQSCYVSHJZ
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答