javascript (0, obj.prop) () usage

I first saw this strange usage is in the babel of source code, in fact, it works so that the prop can not get this in this method, and thus can not do the work with another variable or method in the class.

obj.prop()

This is a method call, prop method where you can get to this

var func = obj.prop;

func()

This is a function call

(0, obj.prop)()

This is a function call, put a comma before the method call (,), causes the reference js solution, into a function call to invoke the method.

Reference variable has three operations:

GetValue (V): If V is a value V returns, if one is referenced, the return reference value V, i.e., returns the final value.

PutValue (V, W): reference value of the variable V to W.

GetThisValue (V): V is only in reference to a property called, returns a reference variable.

The assignment and commas will make reference variables dereference, thereby calling GetValue () to get the final value, so no this, become the method call.

http://2ality.com/2015/12/references.html

Guess you like

Origin www.cnblogs.com/helloz/p/10991814.html