The logical negation of the result of executing an anonymous function

0 like 0 dislike
4 views
The facebook source has been found the sample code below. Can you please tell me the purpose and meaning of the use of such reception:

!function(){
...
}();


Original:

!function(){
var c = document.documentElement;
var b = 'child_focused';
var d = 'DOMControl_placeholder';
var a = function(e){
e = e || window.event;
var f = e.target || e.srcElement, h = f.getAttribute('placeholder');
if (h) {
var g = Parent.byClass(f, 'focus_target');
if ('focus' == e.type || 'focusin' == e.type) {
if (f.value == h) {
f.value = ";
CSS.removeClass(f, d);
g && CSS.addClass(g, b);
}
}
else
if (f.value == ") {
CSS.addClass(f, d);
f.value = h;
g && CSS.removeClass(g, b);
}
}
};
c.onfocusin = c.onfocusout = a;
if (c.addEventListener) {
c.addEventListener('focus', a, true);
c.addEventListener('blur', a, true);
}
}();


Thank you!
by | 4 views

3 Answers

0 like 0 dislike
The meaning is. If you do not write !, the function is recognized as a function declaration, but it could not immediately call, i.e.
\r
function (){ /* body */ }() 

Will cause an error. But adding the operator, we "converted" our function declaration to function expression, which it is already possible to call on the above scheme. Standard equivalent
\r
(function (){ /* body */ })() 
longer by 1 character.
by
0 like 0 dislike
!function(){}() without return'and in any case returns true.
And the meaning depends on the context in which this function is executed.
by
0 like 0 dislike
In this case, returning true as the result doesn't matter. The function is executed and the result is never assigned to, and will not be returned. What is the point then to use this design?
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,758 users