正在研究一些js代码性能,并看到这一方法:
window.sample = {
foo: function foo(a,b){
// code goes here
}
bar: function bar(a,b){
// code goes here
}
}
您为什么在“职能”一词之后减速函数名称?
帮助调试的剂量?
是好的还是坏的 还是不必要的?
正在研究一些js代码性能,并看到这一方法:
window.sample = {
foo: function foo(a,b){
// code goes here
}
bar: function bar(a,b){
// code goes here
}
}
您为什么在“职能”一词之后减速函数名称?
帮助调试的剂量?
是好的还是坏的 还是不必要的?
它们不是为Foo和bar属性指定匿名功能,而是指定指定职能。
它可以有助于调试 : 这唯一不同之处, 据我所知, 就是您可以看到调用堆叠中显示的函数名称, 而不是“ 静音匿名函数 ” 。
唯一的理由是,您可以在函数内使用该函数本身而不提及对象:
foo: function foo(a,b){
return a > 0 ? a + foo(a-1,b) : b;
}
注意在浏览器之间对命名函数字典的这种支持不一致, 所以您应该避免使用它 。
这是 named 函数表达式 em> 。 函数的名称仅在函数本身中作为变量可用。 这对循环有用, 例如 :
var obj = {
foo: function foo(node) {
// Do something to node
var childNode = node.firstChild;
while (childNode) {
foo(childNode);
childNode = childNode.nextSibling;
}
}
};
大多数浏览器也通过函数的非标准 name
属性提供函数的名称,该属性有助于在调试或检查堆叠痕迹时识别函数。
IE & lt; 9 执行有缺陷, 所以使用它时需要小心。 详情请见 < a href=" http:// kangax. github. com/ nfe/ " rel= "nofollow" > Juriy Zaytsev 有关该主题的出色文章 < /a > 。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.