今天@dont
分享了一道题,看的我晕头转向,想破脑袋也想不出,只能发帖求救了。。。
var guineaPig =(function(){
var key = false;
return {
getKeyFromStomach:function(){
return key;
}
}
})()
intervals.push(
setInterval(function(){
try{
... //补充代码(不允许用到guineaPig变量以及destroy函数)
if(guineaPig.getKeyFromStomach()){
R.destroy('right');
}
}catch(e){
error(e,intervals,R)
}
},200)
)
整道题是这样规则是这样的,代码上下文中的所有函数以及变量都已经有定义好了,我们需要做的只是在try{}块中补充代码,使if语句下面的R.destroy('right')
能够执行。但是补充的代码中不能用到guineaPig变量和不能使用destroy函数
。
求大神指教.. Orz
原题链接:http://jsrobot.tk/#12 (貌似需要科学上网)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
没有亲手去做,以下思路仅供参考,或许错得离谱也不一定哦……
如果我理解无误的话,归根结底,就是要在不引用
guineaPig
的前提下,让guineaPig.getKeyFromStomach()
返回true
,从而顺利执行R.destroy('right')
,对吗?OK,那么我有一个思路:
window
对象guineaPig
是否严格按照你给出的实例代码而定义的?如果是,那么window.guineaPig
应该是存在的"guineaPig"
guineaPig
变量,但是可以使用"guineaPig"
字符串吧?window[i].getKeyFromStomach = function () { ... }
的方式重新定义该方法,这样就应该可以了吧?window.key = true?