01
Overview
this is determined by call site. Default: global object. Implicit: obj.method(). Explicit: call/apply/bind. new: new object. Arrow functions inherit this lexically (cannot be rebound).
bash
const obj={val:1,get(){return this.val;}};
obj.get(); // 1
const unbound=obj.get;
unbound(); // undefined (strict mode)
const bound=obj.get.bind(obj);
bound(); // 102
Best Practices
Arrow functions inherit this (no own this). Use bind for permanent binding. Use call/apply for one-time binding. In classes, methods have this bound to instance. Beware callback this (use arrow or bind). Strict mode default this is undefined.
Ready to try this Binding Rules?
Visit the official site for the latest version and full documentation.
Visit this Binding Rules