The operator precedence JS

Writing this blog the reason is because of all subjects written yesterday encountered a similar problem.

 

This question is now to take a look, first of all as a comment written, because there are so enhance the function of the first getval () output is 5, then this function call f.getval output 2,

. F () getval () This step is more important to understand:

The first step: first implementation of the code within the function f; f function because there is no use getval var statement, etc., so getval become a global private member function instead of the function f, then returns this = "that is, the window object;

Second step: In this case f () getval () becomes window.getval (); the output is 1 day

 Getval second call: a reference to the above it is also output;

new f.getval (): '.' because the member access priority than new, we first performed foo.getName, to execute new, can be considered as = "new (f.getval) (), new f in return. examples getval output 2;

new f () getval ():. When this is mainly hesitant to perform f () or new, is because the new arguments, so the first new, = "(new f ()) getval, that is called Yes. getval (on) f, because () did not find in their own getval in f, so go find the prototype, the output of 3

new new f () getval ():. The above can know the new parameters will be preferentially executed so:

The first step: new (new f () getval.) ()

Step two: new ((new f ()) .getval) ()

First calculation new foo(), the acquisition getName, to obtain content in new () calculation, then call;

I.e. new ((new f ()) .getval) () = "new (f.prototype.getval) (), so the output is 3.

Reference article: https://www.jianshu.com/p/412ccd8c386e

Guess you like

Origin www.cnblogs.com/ruilin/p/11695954.html