Since I'm converting the Javascript code tonode.js, I'm changing the old code to adapt it toES6, using "Class< /strong>" and "Module" instead of just using the "Function" component.
I updated the server side first and everything went well. But now, I'm trying to get into the client and I'm having trouble converting the old encoding to the new one.
In the following example you can find 2 applets:
The "module" applet consists of 2 files: "FooClass.js" and "Foo_mod.html".
"Components" include "FooComp.js" and "Foo_comp.html".
All 4 files are stored in the same folder. Both applets should display an alert message "x = 7", but the "Module" applet does not, while the old fashion one Done right.However, when you press Ctrl and click the js file name in VS Code, there is no problem in reaching the js file from the html code. So there must be something wrong with my new code, but I can't find it. If anyone can help me, thanks in advance...
FooClass.js:
class Foo { constructor() { this.foo = ""; } cinq (x) { //(real)->real return x + 5; } } module.exports = Foo;
Foo_mod.html:
Page2
2 - Old method applet: (works fine)
FooComp.js
function cinq (x) { //(real)->real return x + 5; } // end of file FooComp.js
Foo_Comp.html:
FooComp
You should modify the
FooClass.js
file to use theES6 export
syntaxinstead ofmodule.exports
:You can use the
import
statementto import the
Foo
class: