0

Need your assistance. I have a function that was defined in onclick event and when i try to call it later there is an error that says function undefined.

author.onclick = function authorSlideInfo(event){
    // do work
}

authorSlideInfo.then(() => {
   // do work
}

Function returns a promise and i want to do something else after it ends. Is my function not in global scope? How to overcome this?

Zobla
  • 123
  • 2
  • 7
  • 1
    It doesn't add it to a new scope but you're trying to call it by name. However, the function is not bound to that name, since you just have a function expression - it's assigned to `author.onclick` and that's it. The name serves nearly no purpose at all - you cannot call it via that. – VLAZ Apr 13 '20 at 22:47
  • 4
    You're also not even calling the function, since there's no `()` after it. – Barmar Apr 13 '20 at 22:48
  • Also relevant: [var functionName = function() {} vs function functionName() {}](https://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname/) – VLAZ Apr 13 '20 at 22:48
  • Problem solved, thank you – Zobla Apr 13 '20 at 23:05

0 Answers0