Answer the question
In order to leave comments, you need to log in
How to understand closures in Javascript?
The article about higher-order functions on habrahabr.ru/post/241155 has the following code:
function noisy(f) {
return function(arg) {
console.log("calling with", arg);
var val = f(arg);
console.log(f);
console.log("called with", arg, "- got", val);
return val;
};
}
noisy(Boolean)(0);
Answer the question
In order to leave comments, you need to log in
closures
are very simple. the function f is passed as an argument to the noisy function. this is done for callbacks. simple example:
var name = function(f) {
alert(f());
}
name(function() {
return 100;
});
var name = function() {
console.info('Parent function');
return function() {
console.info('Nested function');
}
}
name()();
// должно вывести
// Parent function
// Nested function
Probably because we are talking about functional programming. It says below that the function is not entirely convenient.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question