You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
native (replaceable by a built-in platform feature)
Rationale
auto-bind exists to bind class methods to their instance, which class fields with arrow functions now handle at the language level. both approaches allocate one function per instance, so there's no perf tradeoff.
Availability
class fields are ES2022
Code example (optional)
// beforeimportautoBindfrom'auto-bind';classFoo{constructor(){autoBind(this);}method(){returnthis.value;}}// afterclassFoo{method=()=>this.value;}// if prototype placement matters (spying, super calls, inherited methods):classFoo{constructor(){this.method=this.method.bind(this);}method(){returnthis.value;}}
Activity
[-][Replacement]: auto-bind[/-][+][Replacement]: `auto-bind`[/+]