Destination (0, obj.method) (param1, param2) in abbreviated Composure Compiler code

What is this approach for? For example, from the Google OAuth API:

(0, _.Q)("gapi.auth.authorize", _.Ek.Ff); (0, _.Q)("gapi.auth.checkSessionState", _.Ek.MH); (0, _.Q)("gapi.auth.getAuthHeaderValueForFirstParty", _.Ek.Qe); (0, _.Q)("gapi.auth.getToken", _.Ek.$f); (0, _.Q)("gapi.auth.getVersionInfo", _.Ek.Wk); (0, _.Q)("gapi.auth.init", _.Ek.gb); (0, _.Q)("gapi.auth.setToken", _.Ek.Ym); 

It seems to me like a simple conclusion

 _.Q("gapi.auth.authorize", _.Ek.Ff); _.Q("gapi.auth.checkSessionState", _Ek.MH); ... 

I guess that is not the case. so what's the difference?

+6
source share
1 answer

The compiler guarantees the correctness of the value of "this":

 af() // 'this' value is "a" (0, af)() // 'this' is the default "this" value 

The reason you see this in the OAuth API is because the code uses the "global character conversion compiler". This passage places characters that would otherwise be entered into the global scope for communication by function areas (IIFE) to the object. So, the code is as follows:

 function f(); // some potentially late loaded code f(); 

becomes:

 (function(_){ _.f = function() {}; })(something); (function(_){ _.f(); })(something); 

But here the value of "f" 'this' has changed from the default value of 'this' to "_". To prevent this change, use "(0, _.f) ()" instead.

This is an area where the compiler can improve because it does this even in cases where it can determine that "this" is not used in the body of the function.

+5
source

Source: https://habr.com/ru/post/953206/


All Articles