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

.on events have no 'this' defined #59

Closed
ciknowles opened this issue Jun 5, 2020 · 3 comments
Closed

.on events have no 'this' defined #59

ciknowles opened this issue Jun 5, 2020 · 3 comments

Comments

@ciknowles
Copy link

I noticed when binding to an 'on' event that 'this' is undefined when the handler is called.

For example:
tweakpane.addInput(menu, 'value', someconfig)
.on('change', myfunction);

where
myfunction(value) {
//doing something here
//but 'this' undefined unless you explicitly call 'bind' on the handler function
}

Should 'this' be set to the input interface instance?

Chris

@ciknowles
Copy link
Author

This isn't such a bad idea. It makes you explicitly force the context.

The only issue is that you need to keep references to the InputBindings after addInput calls if you wish to use them later.

Would you consider allowing bindings to be added with a 'key'. Then extending the API to include a getBinding(key) call?

addInput(menu, 'value', {key:'myid',....});

Later on I can then just call tweakpane.getBinding('myid');

Chris

@cocopon
Copy link
Owner

cocopon commented Jun 7, 2020

I don't have a plan to add key because it is not natural, but the first idea (binding handlers to appropriate APIs) looks good.

@cocopon
Copy link
Owner

cocopon commented Jun 8, 2020

Fixed in #69. Please wait for the next release.

@cocopon cocopon closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants