here in this example
function a() { console.log(this.x); }
var x = 10;
a.x = 20;
a.call(a);
The result is 20
Why does this happen?
I know in call method we can send object but here send a function? can we do that? and why does a.x work?
here in this example
function a() { console.log(this.x); }
var x = 10;
a.x = 20;
a.call(a);
The result is 20
Why does this happen?
I know in call method we can send object but here send a function? can we do that? and why does a.x work?
Copyright © 2021 Jogjafile Inc.
The call() method can be used to invoke a function with a specific
thisvalue, which can be an object or any other value.In this example,
a.xworks because functions in JavaScript are also objects and can have properties added to them. So,a.xadds a propertyxto the functiona.