博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
十一 JS继承
阅读量:4506 次
发布时间:2019-06-08

本文共 1751 字,大约阅读时间需要 5 分钟。

// time:2016.2.1// des:继承function Enemy() {     this.level = 50;      console.log("Enemy constructor"); }Enemy.prototype.attack_play = function(){    console.log("attack_play");};Enemy.prototype.wudiai = 100;Enemy.wudiai = "1213";Enemy.gongji = function(){    console.log("gongji   asasasd "+ Enemy.wudiai);}function BossEnemy(){    Enemy.call(this);    console.log("Boss constructor");}// 写法1// BossEnemy.prototype = {constructor: BossEnemy,};// for(var i in Enemy.prototype){//     BossEnemy.prototype[i] = Enemy.prototype[i];// }// 写法2var a = function (){};a.prototype = Enemy.prototype;BossEnemy.prototype = new a();BossEnemy.prototype.boss_attack = function(){    console.log("boss_attack");};BossEnemy.staticFunc = function(){    console.log("staticFunc called!");};var bos = new BossEnemy();bos.boss_attack();bos.attack_play();BossEnemy.staticFunc();console.log("==========================");BossEnemy.prototype.attack_play = function(){    Enemy.prototype.attack_play.call(this);    console.log("BossEnemy attack play!");}bos.attack_play();console.log("*****************************");// 写法三 js6class BingEnemy extends Enemy{    constructor(){        super();        this.flag = true;        this.name = "通天教主";        this.level = 100;            }        static staticFunc(){        console.log("static func called!");    }    get BingName(){        return this.name;    }    set BingName(value){        this.name = value;    }};BingEnemy.haha ="123";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("============================");

 

转载于:https://www.cnblogs.com/jadeshu/p/10663572.html

你可能感兴趣的文章
C#高级编程
查看>>
JS实现从照片中裁切自已的肖像
查看>>
使用 https://git.io 缩短 a GitHub.com URL.
查看>>
拷贝、浅拷贝、深拷贝解答
查看>>
四元数
查看>>
StackAndQueue(栈与队列)
查看>>
URLOS安装、升级、卸载
查看>>
在win7下配置sql2005允许远程访问
查看>>
aspose.cell 设置excel里面的文字是超链接
查看>>
POJ 1067 取石子游戏
查看>>
django开发框架-view & template
查看>>
[Linux]systemd和sysV
查看>>
时间日期正则表达
查看>>
JSON.NET 简单的使用
查看>>
java 集合 HashMap
查看>>
HackerRank "Training the army" - Max Flow
查看>>
jquery next()方法
查看>>
SQLHelper
查看>>
五年修炼SEO、一年五万,多嘛?(看时间如何管理?五点论……)
查看>>
Mesos源码分析(16): mesos-docker-executor的运行
查看>>