0

Is it possible to create global function with ES6 ? I would like use some function on my twig.

The problem is that my function is in an ES6 module. In twig, it is not possible to import the function.

Do you have an idea to counter this problem?

Stéphane R.
  • 1,386
  • 3
  • 19
  • 37
  • 1
    Same way as you would have in ES5, nothing's changed, assign it to the [global object](http://stackoverflow.com/questions/9642491/getting-a-reference-to-the-global-object-in-an-unknown-environment-in-strict-mod). Or: https://github.com/ljharb/System.global – CodingIntrigue Nov 28 '16 at 08:18
  • `var global = (1,eval)('this');` is the global function ? I'm not sure I understood very well – Stéphane R. Nov 28 '16 at 08:54
  • 1
    `var global = (1,eval)('this'); global.yourFunction = () => alert("Hello, World");`. `global` is the global context. `yourFunction` is the global function. – CodingIntrigue Nov 28 '16 at 09:09
  • Haaa okey, I understand :) It work nice, thank you ! – Stéphane R. Nov 28 '16 at 09:16

0 Answers0