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

Existential operator doesn't bind scope as expected when used with functions #29

Open
davej opened this issue Aug 6, 2015 · 2 comments

Comments

@davej
Copy link

davej commented Aug 6, 2015

Take the following code:

global.install-win??.focus??()

An over-simplified version of the assignments/executions in JS might be:

tmp$0 = global.installWin;
tmp$1 = tmp$0.focus;
tmp$1();

This doesn't retain the correct function scope and may cause bugs/errors. I would suggest:

tmp$0 = global.installWin;
tmp$1 = tmp$0.focus;
tmp$1.bind(tmp$0)(); // or perhaps `func.apply()` is better (more performant)?
@davej
Copy link
Author

davej commented Aug 6, 2015

Might be cool to soak up 'x is not a function' errors too:

if (typeof(tmp$1) === 'function') {
   tmp$1.bind(tmp$0)();
}

@davej
Copy link
Author

davej commented Aug 6, 2015

Thinking about it... might be easier to not bind at all and just call the function in the context of the parent scope:

tmp$0.focus();

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