
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 0.50 KB | hits: 7 | expires: Never
// define a function
function foo() {
var bar = 1;
};
// or
var foo = function() {
var bar = 1;
};
// invoke foo
foo();
// if:
// foo === function() { var bar = 1; }
//
// then:
// foo() is equivalent to (function() { var bar = 1; })();
// why do this:
(function() {
var bar = 1;
})();
// instead of this?
var foo = function() {
var bar = 1;
};
foo();
// because the latter leaves a reference to foo in the
// local scope, which you may not need