Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SystemJS newModule() with class (function), not object

I have some global classes(JS classes with prototype syntax) that need to be manually added to registry with System.set(moduleName, Module). Since second parameter is of type Module, I need to use System.newModule(object).

But, if I pass a non-object to System.newModule(), it throws - Uncaught TypeError: Expected object.

Am I doing this wrong? Is there another way to do this?

like image 526
andree Avatar asked May 20 '26 14:05

andree


1 Answers

System.set(System.normalizeSync('./something'), System.newModule({
  __useDefault: function() {
      console.log('do stuff');
  }
}));

Basically all you need to do is to have your function/non-object defined in defalut key and use option: __useDefault: true

like image 50
Ascon Avatar answered May 22 '26 04:05

Ascon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!