How to declare a function in javascript so that it can be called like this: f()() , where f is the name of the function?

  • What is the purpose of this event? - PinkTux
  • one
    function f must return a function. - Grundy Nov.
  • In the test task there was such a question - user228109 Nov.
  • For this no twists with brackets are needed. For example . - PinkTux
  • one
    Two times brackets mean that the operator of brackets is applied to f and then to the result of f (). In javascript, the parenthesis operator is applicable only to functions, that is, f () should return the function for which the second () - nick_n_a applies

2 answers 2

All figured out, here is an example

 var f = function() { var func = function() { return 'result'; } return func; } f()(); 

Displays "result"

  • Thanks to Grundy for the tip))) - user228109
 var f = function() { return function() { return 'result'; } }