Define a function with a name in the string

I need to define a function with a name that I have in the string.

Not a big deal, right?

window[fnName] = function(...args) {
  // ...
}

But what if I cannot access the window object? Like inside of Worker, for example.

Is it possible to do it without window and without eval()?

114 thoughts on “Define a function with a name in the string”

Leave a Comment