Priority of JavaScript

clipboard.png
Why does new do modify the this binding? isn"t the function of new to create an object and attach the returned value to the object, or bind the this to the object of var? it should not do anything to obj1.a, should it?

Dec.09,2021

look here. The sentence

bar as an ordinary function, its this has been bound to obj1;
but ins
ide the constructor, this points to the newly created object; the
new keyword gives you three things:
var o = new Object ();
this = o;
.
return o;
this is thus changed;
therefore, bar does not return a value, but you can get an instance as a constructor.


call foo.bind (obj1) to get bar,. When you perform bind, apply or call operations on bar, you cannot change the obj1, that bar has bound, but you can change it with new.

Menu