参考回答:
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;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)