We want to make this open-source project available for people all around the world.

Help to translate the content of this tutorial to your language!

back to the lesson

Bound function as a method

importance: 5

What will be the output?

function f() { alert( this ); // ? } let user = { g: f.bind(null) }; user.g();

The answer: null.

function f() { alert( this ); // null } let user = { g: f.bind(null) }; user.g();

The context of a bound function is hard-fixed. There’s just no way to further change it.

So even while we run user.g(), the original function is called with this=null.