-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using es6 super sugar for a method/function fails #156
Comments
@dkebler Welcome back and thank you for reporting this issue.
Yes, currently tests are run against Node.js 4, 6, 8, 10 and 12. See here in travis.yml. The issue can also be reproduced with the following test program: const Gpio = require('onoff').Gpio;
class InputPin extends Gpio {
constructor(pin) {
super(pin, 'in');
}
read() {
console.log('InputPin#read');
return super.read();
}
}
let button = new InputPin(4);
setInterval(() => {
button.read().then(value => {
if (value === 1) {
console.log('button pressed');
} else {
console.log('button released');
}
});
}, 1000); The issue occurs due to a recent optimization. Part of the optimization is that I'll fix this asap. If you would like to workaround the issue on your system until a fix is published change this line in onoff.js: this.read((err, value) => { to: Gpio.prototype.read.call(this, (err, value) => { |
Phew... just couldn't grok why my code was blowing the stack. Took me awhile to track this down but glad it was something in onoff not my code. For now I am fine. When you push a fix and close this issue I'll know I can try out the fix. Thx |
fixed with b6f3ce3 in [email protected] @dkebler once again, thank you for reporting this issue. |
finally getting back this...just confirming that a super.read() now works! with 4.1.3. Thx |
Never had this issue before when extending using ES6 and I have a whole library where I use "super" methods.
but extending onoff Gpio if I create a method "read" and then call super.read within it calls my new read method instead of onoff's Gpio read function. I assume it does this cause creating the read method is somehow overwriting or masking the parent function/method. Is there something in the onoff prototype that precludes using the es6 super sugar?
BTW I am using a latest node in this case 12.4. Do you always run your tests against latest node? If not is this the issue maybe???
For now I just changed my method name so as not to superceed the read method but this is an issue I've never had extending any other object using es6 class syntax.
here is the the way I had it coded
Here I just chose a different name that then calls onoff read. It works fine but I'm scratching my head why something that's always worked for me (super method calls) is not in this case.
The text was updated successfully, but these errors were encountered: