介绍
这期内容当中小编将会给大家带来有关如何在JavaScript中继承定义,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
& lt; script> function 敌人(),{, this.level 才能=,50岁,, console.log才能(“移动速度;constructor");, } 时间=Enemy.prototype.attack_play 函数(){ console.log才能(“attack_play"); }; 时间=Enemy.prototype.wudiai 100; 时间=Enemy.wudiai “1213”; 时间=Enemy.gongji 函数(){ console.log才能(“gongji , asasasd “+, Enemy.wudiai); } function BossEnemy () { Enemy.call才能(这个); console.log才能(“Boss constructor"); }//,写法1//,BossEnemy.prototype =, {BossEnemy,构造函数:};//,(var 小姐:拷贝Enemy.prototype) {//,,,BossEnemy.prototype[我],=,Enemy.prototype[我];//,}//,写法2 var a =, function () {}; 时间=a.prototype Enemy.prototype; 时间=BossEnemy.prototype new (); 时间=BossEnemy.prototype.boss_attack 函数(){ console.log才能(“boss_attack"); }; 时间=BossEnemy.staticFunc 函数(){ console.log才能(“staticFunc 叫做!“); }; var bos =, new BossEnemy (); bos.boss_attack (); bos.attack_play (); BossEnemy.staticFunc (); console.log (“==========================?; 时间=BossEnemy.prototype.attack_play 函数(){ Enemy.prototype.attack_play.call才能(这个); console.log才能(“BossEnemy  attack 玩!“); } bos.attack_play (); console.log (“* * * * * * * * * * * * * * * * * * * * * * * * * * * * *“);//,写法三,js6 class BingEnemy  extends 敌人{ 构造函数才能(){ ,,,超级(); ,,,this.flag =,真的; ,,,this.name =,“通天教主“; ,,,this.level =, 100; ,,} static 才能;staticFunc () { ,,,console.log (“static  func 叫!“); ,,} get 才能;BingName () { ,,,return this.name; ,,} set 才能;BingName(值){ ,,,this.name =,价值; ,,} }; BingEnemy.haha =?23“;; let bing =, new BingEnemy (); console.log (bing); BingEnemy.staticFunc (); bing.attack_play (); console.log (bing.BingName); 时间=bing.BingName “jade"; console.log (bing.BingName);//console.log (BingEnemy.wudi); console.log (“============================?; & lt;/script>
运行结果:
上述就是小编为大家分享的如何在JavaScript中继承定义了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。