. .
function foo(){
alert("This is an alert");
}
() :
foo();
(, **, . **).
, rvalue,
var f = function (){
alert("This is an alert");
};
() :
f();
:
(function (){
alert("This is an alert");
})();
, ! (.. ).
:
(function( window, undefined ) {
})(window);
:
var f = function( window, undefined ) {
};
f(window);
( f) 2 : window undefined. 1- window ( , ). , . , , Javascript undefined ( ). , () undefined undefined.
- . ( , , - JS script undefined - !)
See:
https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Functions
https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Expressions_and_Operators
EDIT:
As @FelixKling comments, function expressions need not be anonymous; they may have names.
var f = function foo(){
alert("This is an alert");
}
This is an interesting article about their use.
source
share