首页 新闻 会员 周边

arguments.callee

0
悬赏园豆:10 [已解决问题] 解决于 2015-08-10 08:26
function repeat(fn, times, delay) {
    return function() {
        if(times-- > 0) {
            fn.apply(null, arguments)
            var args = Array.prototype.slice.call(arguments)
       alert(arguments.callee)
var self = arguments.callee setTimeout(function(){self.apply(null,args)}, delay) } } } function comms(s) { alert(s) } var somethingWrong = repeat(comms, 3, 2000); somethingWrong("Can you hear me, major tom?")

arguments.callee指向正在执行的函数。请问var self = arguments.callee为什么self会等于function(),前一句alert(arguments.callee)输出的是整个repeat函数代码?不是很理解正在执行函数的意思,往指导!

TinDin的主页 TinDin | 初学一级 | 园豆:126
提问于:2015-08-09 14:07
< >
分享
最佳答案
0

问题似乎没有描述清楚。

主要在于理解正在执行的函数,在执行repeat函数的时候,其代码只有一个return语句,returne的是一个匿名函数。注意这里只是返回匿名函数的引用,而并没有执行该匿名函数。匿名函数被赋值给somethingWrong变量。然后执行somethingWrong函数,也就是执行匿名函数,这时候arguments.callee当然指向的是匿名函数了。

收获园豆:10
ThreeTree | 小虾三级 |园豆:1490 | 2015-08-09 15:06

谢谢啦,我已经理解啦。每个函数都有一个arguments,callee是它的一种属性。如果我有其他函数的arguments,我也可以arguments.callee执行其他函数。

TinDin | 园豆:126 (初学一级) | 2015-08-09 15:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册