In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "can you still use arguments.callee", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "can you still use arguments.callee" this article.
Callee is a property of the arguments object. It can be used for functions that are currently executing in the body of the function that references the function. This is useful when the name of a function is unknown, such as in a function expression that has no name (also known as an "anonymous function").
Can argumentscallee still be used?
Warning: in strict mode, version 5 ECMAScript (ES5) forbids the use of arguments.callee (). Avoid using arguments.callee () when a function must call itself, by either giving the function expression a name or using a function declaration.
Why was arguments.callee removed from ES5 strict mode?
(adapted from aStackOverflowanswerbyolliej)
Earlier versions of JavaScript did not allow named function expressions, and for this reason, you cannot create a recursive function expression.
For example, the following syntax makes sense:
Functionfactorial (n) {
Return! (n > 1)? 1:factorial (NMur1) * n
}
[1, 2, 3, 4, 5] .map (factorial)
But:
[1, function 2, 3, 4, 5] .map (function (n) {
Return! (n > 1)? 1:/*whatgoeshere?*/ (NMur1) * n
})
Not this one. To solve this problem, arguments.callee has been added. And then you can do this.
[1, function 2, 3, 4, 5] .map (function (n) {
Return! (n > 1)? 1:arguments.callee (NMur1) * n
})
However, this is actually a very bad solution, because this (and other arguments,callee, and caller problems) makes it impossible to implement inline and tail recursion under normal circumstances (you can debug a few individual examples, but even the best code is the second-best option because (the JavaScript interpreter does unnecessary checks). Another main reason is that recursive calls get a different this value, for example:
Varglobal=this
VarsillyFunction=function (recursed) {
If (! recursed) {returnarguments.callee (true);}
If (this is the reason why global) {
Alert ("Thisis:" + this)
} else {
Alert ("Thisistheglobal")
}
}
SillyFunction ()
The above is all the contents of the article "can arguments.callee still be used?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.