I am using jQuery 1.7.2
I have two ways of writing the same code. One way seems more verbose and the other seems more flexible. Is this the only difference? Is there any performance difference? Is there a better way of writing these?
Code sample #1 uses two named functions so they are reusable. It's a bit more code.
Code sample #2 uses two unnamed functions that work only on the hover method. It's less code but not reusable.
Any thoughts or comments?
// CODE SAMPLE #1
// IPP FUNCTIONS
var openIPP = function openIPP() {
$IPPNonDefault.stop().animate({"height": OpenHeight}, DownRate);
}
var closeIPP = function closeIPP() {
$IPPNonDefault.stop().animate({"height": "0px"}, UpRate);
}
// IPP ACTIONS
$IPPWrapper.mouseover(openIPP).mouseout(closeIPP);
// CODE SAMPLE #2
$IPPWrapper.hover(
function() {
$IPPNonDefault.stop().animate({"height": OpenHeight}, DownRate);
},
function() {
$IPPNonDefault.stop().animate({"height": "0px"}, UpRate);
}
);
function foo() {}
orvar foo = function () {};
, notvar foo = function foo() {};
. The last method can have some very odd side-effects in IE<9, and is more prone to typos. \$\endgroup\$