这些迭代有什么区别?
这些迭代有什么区别:
var recordId;
for(recordId in deleteIds){
...
}
它
for(var recordId in deleteIds){
...
}
说隐式定义(它是什么),它们之间有性能差异吗?
What are the differences of that iterations:
var recordId;
for(recordId in deleteIds){
...
}
and
for(var recordId in deleteIds){
...
}
It says implicit definition(what is it), is there a performance difference between them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这两个示例是等效的,但是第一个示例可能来自遵循 JavaScript 中推荐的模式,即在每个函数的顶部声明所有变量。
示例:
更多说明可以在这里找到 JSLint 错误:将所有“var”声明移至函数顶部
the two samples are equivalent, however the first may come from following a recommended pattern in JavaScript which is declaring all variables at the top of every function.
Sample:
More explanation on this can be found here JSLint error: Move all 'var' declarations to the top of the function
“隐式声明”是指在使用
var
声明变量之前先为其赋值的变量。该场景将声明的变量保留在最大可能的范围(“全局”范围)中。但是,在您的两个代码示例中,
recordId
是在分配之前声明的 (var recordId
),因此没有问题。至于你的另一个问题,不,没有明显的性能差异。
An "implicit declaration" is a variable that is assigned a value before it is declared using a
var
. The scenario leaves the variable declared in the largest possible scope (the "global" scope).However, in both your code examples,
recordId
is declared before it is assigned (var recordId
), so there's no problem.As to your other question, no, there is no noticeable performance difference.