DEV Community

Discussion on: Is "this" really that complicated in JavaScript?

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman

You can also manipulate this context:

console.log(this); // `Window`

function onClick() {
    console.log(this);
}

onClick(); // `Window`

button.addEventListener('click', onClick);
button.click(); // `button`

onClick.bind(new F1);
onClick(arg1, arg2); // `F1`

onClick.call(new F2, arg1, arg2); // `F2`
onClick.apply(new F3, [arg1, arg2]); // `F3`
Enter fullscreen mode Exit fullscreen mode