编写代码,满足以下条件: (1)Hero;执行结果为 Hi! This is 37er (2)Hero.kill.recover;执行结果为 Hi! This is 37er Kill 1 bug R

编写代码,满足以下条件: (1)Hero;执行结果为 Hi! This is 37er (2)Hero.kill.recover;执行结果为 Hi! This is 37er Kill 1 bug R,第1张

编写代码,满足以下条件: (1)Hero;执行结果为 Hi! This is 37er (2)Hero.kill.recover;执行结果为 Hi! This is 37er Kill 1 bug R

参考回答

function Hero(name){        let o=new Object();        o.name=name;        o.time=0;        console.log("Hi! This is "+o.name);        o.kill=function(bugs) { if(bugs==1){   console.log("Kill "+(bugs)+" bug"); }else { setTimeout(function () { console.log("Kill " + (bugs) + " bugs"); }, 1000 * this.time); } return o;        };        o.recover=function (bloods) { console.log("Recover "+(bloods)+" bloods"); return o;        }        o.sleep=function (sleepTime) {        o.time=sleepTime;        return o;    }    return o;}

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4889478.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存