我是靠谱客的博主 高高刺猬,这篇文章主要介绍arguments.callee的用法,现在分享给大家,希望可以做个参考。

1.今天在看高阶函数,其实currying的一个函数中,有那个arguments.callee,表示不见过,查了查。

复制代码
1
2
3
4
5
6
arguments.callee 在哪一个函数中运行,它就代表哪个函数。 一般用在匿名函数中。 在匿名函数中有时会需要自己调用自己,但是由于是匿名函数,没有名子,无名可调。 这时就可以用arguments.callee来代替匿名的函数

  

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var currying = function ( fn ) { var args = []; return function () { if( arguments.length ===0 ){ return fn.apply( this, args); }else{ [].push.apply(args, arguments); return arguments.callee; } } }; var cost = (function () { var money = 0; return function () { for( var i = 0,l = arguments.length; i < l; i++){ money += arguments[i]; } return money; } })() var cost = currying( cost ); cost(100); cost(200); cost(300); alert(cost()) //600

  

转载于:https://www.cnblogs.com/chenjinxinlove/p/5851073.html

最后

以上就是高高刺猬最近收集整理的关于arguments.callee的用法的全部内容,更多相关arguments.callee内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部