R
RobG
There has been a discussion on the iPhone web development group where
an opinion has been expressed that function expressions are bad for
performance and can be avoided by using function declarations.
For example (in a trivial case, the function body would do processing
depending on various parameters passed) instead of:
function foo(x) {
var a = function(){x};
return a;
}
one could use:
function foo(x) {
function a(){x};
return a;
}
The claim is that the declared internal function is more efficient
than the the assignment of an anonymous function. My testing shows
that there isn't any significant difference in performance between the
two approaches in Firefox and that in Safari the anonymous function
version is faster so the performance issue seems moot - the test
involved calling each function several thousand times from another
function.
Is the test appropriate? Are there any other concerns besides code
style preference?
an opinion has been expressed that function expressions are bad for
performance and can be avoided by using function declarations.
For example (in a trivial case, the function body would do processing
depending on various parameters passed) instead of:
function foo(x) {
var a = function(){x};
return a;
}
one could use:
function foo(x) {
function a(){x};
return a;
}
The claim is that the declared internal function is more efficient
than the the assignment of an anonymous function. My testing shows
that there isn't any significant difference in performance between the
two approaches in Firefox and that in Safari the anonymous function
version is faster so the performance issue seems moot - the test
involved calling each function several thousand times from another
function.
Is the test appropriate? Are there any other concerns besides code
style preference?