Skip to content
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

Executing constructor in class from module doesn't pass arguments #1601

Closed
gfwilliams opened this issue Jan 21, 2019 · 1 comment
Closed

Comments

@gfwilliams
Copy link
Member

gfwilliams commented Jan 21, 2019

Modules.addCached("mod",`
class b {
  constructor(a) {
    console.log("Argument",a);
    if (a!="Foo") throw "No argument passed!";
  }
}
exports = b;`);

mB = new (require('mod'))("Foo");

Fails, but

class b {
  constructor(a) {
    console.log("Argument",a);
    if (a!="Foo") throw "No argument passed!";
  }
}

mB = new b("Foo");

works, as does:

Modules.addCached("mod",`
function b(a) {
  console.log("Argument",a);
  if (a!="Foo") throw "No argument passed!";
}
exports = b;`);

mB = new (require('mod'))("Foo");

http://forum.espruino.com/conversations/329854/#comment14581420

This worked in 2v00

@gfwilliams
Copy link
Member Author

Ok, comparing traces of the object it seems this is because in a class the scope gets moved to the front of the function (before parameters), when the order actually matters during execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant