在对象中声明函数名,为什么? [英] declare function name in object, Why?
本文介绍了在对象中声明函数名,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在研究一些js代码性能并看到了这种方法:
Was working on some js code performance and saw this approach:
window.sample = {
foo: function foo(a,b){
// code goes here
}
bar: function bar(a,b){
// code goes here
}
}
有什么理由吗为什么你会在函数一词之后减速函数名?
is there any reason why you would decelerate the function name after the word "function" ?
它有助于调试吗?
是好还是坏或只是不必要?
is it good or bad or just unnecessary?
推荐答案
而不是为foo和bar属性分配匿名函数,它们正在分配命名函数。
instead of assigning an anonymous function to the foo and bar properties, they are assigning named functions.
它可能有助于调试:我知道的唯一区别是你会看到函数的名称显示在调用堆栈中而不是javascript匿名函数
it can be helpful for debugging: the only difference this makes, that i know of, is that you will see the names of the functions show up in the call stack instead of "javascript anonymous function"
这篇关于在对象中声明函数名,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文