Больше возможностей JavaScript. Если вы видите, что функция вызывается как foo()()
или foo() ('hello')
, это означает, что foo возвращает другую функцию, а параметр во втором "()", такой как 'hello' в foo() ('hello')
, передается функции, возвращаемой функцией foo ().
Пример
сохранить приведенный ниже код в качестве образца. js и выполнить его, используя node sample
foo()() // return undefined, as empty parameter ( parenthesis ) are passed though expecting one
foo()('hello') // param 'hello' is passed to bar when it is returned inside foo
foo()('hello','world') //both hello and world are passed, but only hello is printed, as bar expect only 1 param
function foo() {
return bar
}
function bar (param) {
console.log('bar : '+param)
}
Результаты
bar : undefined
bar : hello
bar : hello