Is there any performance / memory hit differential among the three following styles?
Exhibit A:
var func = function() {
// do some magic
}
$("#div").somePlugin({someEvent: func});
Exhibit B:
$("#div").somePlugin({someEvent: function() {
// do some magic
});
Exhibit C:
function func() {
// do some magic
}
$("#div").somePlugin({someEvent: func});
There might be a little, slightly (really slightly) better performance for the function expression:
That is a such called
function expression. The otherside, thefunction statementis your third example:Function statements are converted internally into function expressions by
ECMA-/Javascript, so thats the reason why it might(!) be slighty faster, but really, nothing to worry about.Your B: example shows an
anonymous function, which also has no performance impact over the A and C.