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
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
Create headers by underlining text with ==== or ----
To *italicise* text put one asterisk each side of the word
To **bold** text put two asterisks each side of the word
Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png) That's the hard one: exclamation, square brackets and then the URL to the image in brackets.
* Create lists by starting lines with asterisks
1. Create numbered lists by starting lines with a number and a dot
> Quote text by starting lines with >
Mention another user by @username
For syntax highlighting, surround the code block with three backticks:
```
Your code goes here
```
Just like Github, a blank line must precede a code block.
If you upload more than 5 files we will display all attachments as thumbnails.
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