I want to call a method of the calling class within a module. This worked fine in Version 2v00 of espruino. After updating to 2v01 I get an error with the same code.
This is the calling program:
class a {
constructor() {
this.mB = null;
}
init() {
this.mB = new (require('http://192.168.88.117:8081/b.js'))(this);
this.mB.perform();
}
say(text) {
console.log(text);
}
}
var x = new a();
x.init();
And this is the module:
class b {
constructor(a) {
this.a = a;
}
perform() {
console.log('class b called');
this.a.say("I'm in b");
}
}
exports = b;
The output shows as follows:
Error: Line 8: Unexpected reserved word in http://192.168.88.117:8081/b.js
>
____ _
| __|___ ___ ___ _ _|_|___ ___
| __|_ -| . | _| | | | | . |
|____|___| _|_| |___|_|_|_|___|
|_| espruino.com
2v00 (c) 2018 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate
Flash map 4MB:512/512, manuf 0xef chip 0x4016
>class b called
I'm in b
Disconnected
>
Found ESP8266_4MB, 2v01
>
Connected to COM4
Error: Line 8: Unexpected reserved word in http://192.168.88.117:8081/b.js
>
____ _
| __|___ ___ ___ _ _|_|___ ___
| __|_ -| . | _| | | | | . |
|____|___| _|_| |___|_|_|_|___|
|_| espruino.com
2v01 (c) 2018 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate
Flash map 4MB:512/512, manuf 0xef chip 0x4016
>class b called
Uncaught Error: Cannot read property 'say' of undefined
at line 2 col 11
this.a.say("I'm in b");
^
in function "perform" called from line 10 col 21
this.mB.perform();
^
in function "init" called from line 19 col 8
x.init();
^
>
It seems that the parameter for the constructor is not passed anymore in 2v01
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I want to call a method of the calling class within a module. This worked fine in Version 2v00 of espruino. After updating to 2v01 I get an error with the same code.
This is the calling program:
And this is the module:
The output shows as follows:
It seems that the parameter for the constructor is not passed anymore in 2v01