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
React 0.13 and Binding #3090
Comments
Don't you think that #3040 might solve the problem? |
Nope! |
Closing this because it's really about JSX and not React (and you already created an issue over there). |
Excerpt from facebook/jsx#27 (comment) as an alternative to using JSX syntax to bind. class ComponentBase {
constructor() {
var excludeFuncs = ['render'];
Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach(function(func) {
if (!excludeFuncs.includes(func) && typeof this[func] === 'function') {
this[func] = this[func].bind(this);
}
}, this);
}
setState(state) {
console.log(state);
}
}
class Component extends ComponentBase {
onClick() {
this.setState({ items: ['test'] });
}
}
var x = new Component;
var y = x.onClick;
y(); @syranide Would it be possible to reopen this, and keep this as discussion for implementing this in the React core, and use the other thread as doing it via JSX, just so we can explore all options. Edit: We can use |
I may be misinformed but I think the whole point of making ES6 classes available is for React to stop trying to provide a type system of its own. Thus autobinding for non- |
I think the point was more to not to have another class system, and just use the standard. Whilst my favourite suggestion is still doing this via JSX, overriding prototypal properties like this is not uncommon. See Edit: forgot there's actually another thread in #3040. Let's keep this closed and continue the discussion there. |
I noticed that the new version of react will require manual binding. This problem will be lessened with ES7, but will still be there. I want to recommend an extension to the JSX language to bind functions to the scope:
=>
over=
(akin to arrow functions).The text was updated successfully, but these errors were encountered: