Javascript Funciton Внутренняя / Внешняя / Переменная Область - PullRequest
0 голосов
/ 05 апреля 2020

Я прочитал документ MDN: Scope и другие ресурсы, но чувствую себя действительно застрявшим.

var funkyFunction = function() {
  return function() {
    return "FUNKY!"
  }
}

// We want to set theFunk equal to "FUNKY!" using our funkyFunction.
// NOTE: you only need to modify the code below this line.

var theFunk = funkyFunction()
theFunk()

1 Ответ

0 голосов
/ 05 апреля 2020

funkyFunction возвращает функцию. Вам нужно немедленно вызвать эту функцию, чтобы она возвратила "FUNKY!" и получила присвоение theFunk:

var funkyFunction = function() {
  return function() {
    return "FUNKY!"
  }
}

// We want to set theFunk equal to "FUNKY!" using our funkyFunction.
// NOTE: you only need to modify the code below this line.

var theFunk = funkyFunction()();
console.log(theFunk);
...