ActionScript 3 中函数和函数文字之间的区别?
ActionScript 3 中以下两个函数定义有什么区别?
f = function(arg) {
// body
}
和
function f(arg) {
// body
}
What is the difference between the following two function definitions in ActionScript 3?
f = function(arg) {
// body
}
and
function f(arg) {
// body
}
您提供的示例几乎没有实际差异。区别实际上是在编译时。值得注意的是,在第一种情况下,f = function,您可以随时重新定义f的值,而在第二种情况下,重新定义f会导致编译器错误。
一般最佳实践是使用第二种。
希望有帮助。
There is very little practical difference in the example you have provided. The difference is really at compile time. The one worth noting is that that in first case, f = function, you can redefine the value of f at anytime, while in the second case, redefining f would cause a compiler error.
General best practices is to use the second.
Hope that helps.