javascript - Is it possible to turn on React.js autobinding for React's class model -


according this blog post feature bounds methods in react.createclass this not built-in in react's class model.

is possible turn on by default?

i know it's possible use this.somemethod = this.ticksomemethod.bind(this); trick manually this, possible do methods? or forced write bind methods?

example of code have now:

import messagestore '../stores/messagestore.js';  export default class feed extends react.component {    constructor() {       this.state = {messages: messagestore.getall()}       //can avoid writing every single method?       this._onchange = this._onchange.bind(this);     }     _onchange() {        this.setstate({messages: messagestore.getall()});    };     // componentdidmount, componentwillunmount , render methods ommited } 

there no feature activate in react currently. it's not option.

you post-process class , automatically bind every function, that's unnecessary in many classes, , adds overhead every call (as code have mixture of functions needing binding , don't).

you'll need decide whether automatic adjustment worth or using bind syntax in context of event callbacks, typical place it's required in javascript, acceptable.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -