How do adjacent parentheses in JavaScript functions work, and where is this documented? -



How do adjacent parentheses in JavaScript functions work, and where is this documented? -

before flag duplicate, note: understand iife is. question not iife's.

the question: why javascript able parse adjacent parentheses, in standard function call? how build - myfunction()() - work? example, here's bit of code test using jasmine:

var element = compile('<div my-directive></div>')(scope);

why go route rather passing scope sec argument? don't believe has keeping global environment clean, , can't find thing particular build anywhere, except concerns iife's. there name construct?

most importantly, please provide sort of authoritative reference (link mdn, ecmascript spec, etc).

this result of 2 rules:

the homecoming value of function calls may used (no need assign variable).

functions objects (they can assigned variables, passed arguments , returned function calls).

the first rule means if have code this:

function () { homecoming { hello : 'world' } }

you can this:

a().hello; // returns 'world';

which same doing without using temporary variables:

var tmp = a(); tmp.hello; // value 'world';

the sec rule means can this:

function b () { homecoming function () { alert('hello world') } } var c = b(); c(); // alerts 'hello world';

combining rule 1 , rule 2 means above can rewritten as:

b()(); // alerts 'hello world';

javascript

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -