I was wondering into the javascript file from the source of http://www.google.com actually i do it often and try to understand what they have done there. today I was wondering inside the files and found some strange function calls. Maybe its a silly thing but I really have no idea what is it and so that I couldn't help by searching for it.
a readable resemble of the code-
var someFunction = function(somaeParamenter){
//do some stuffs;
return something;
}
var someOtherThing = (0, someFunction)(oneParameter);
Please excuse my lack of knowledge.
EDIT:
Source-
i'm using chrome.
while in the http://www.google.com page open, i opened the developer tool. then i opened the sources tab and opened the file https://www.google.com.bd/xjs/_/js/s/c,sb,cr,cdos,vm,tbui,mb,wobnm,cfm,abd,bihu,kp,lu,m,tnv,amcl,erh,hv,lc,ob,r,rsn,sf,sfa,shb,srl,tbpr,hsm,j,p,pcc,csi/rt=j/ver=WUW4ydIf-wI.en_US./am=gA/d=1/sv=1/rs=AItRSTPu52CumknQsh0was81vrM4inla_w
in viewer. this file is the only js file i've seen there. I enabled the "pretty print" and in line 58 you'll find the defination-
_.Va = function(a) {
var b = typeof a;
if ("object" == b)
if (a) {
if (a instanceof window.Array)
return "array";
if (a instanceof window.Object)
return b;
var c = window.Object.prototype.toString.call(a);
if ("[object Window]" == c)
return "object";
if ("[object Array]" == c || "number" == typeof a.length && "undefined" != typeof a.splice && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("splice"))
return "array";
if ("[object Function]" == c || "undefined" != typeof a.call && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("call"))
return "function"
} else
return "null";
else if ("function" == b && "undefined" == typeof a.call)
return "object";
return b
};
and in line 83 you'll see the function is called.
_.Za = function(a) {
return "array" == (0, _.Va)(a)
};
The remainder assignment operator ( %= ) divides a variable by the value of the right operand and assigns the remainder to the variable.
In JavaScript “0” is equal to false because “0” is of type string but when it tested for equality the automatic type conversion of JavaScript comes into effect and converts the “0” to its numeric value which is 0 and as we know 0 represents false value. So, “0” equals to false.
$() The $() function is shorthand for the getElementByID method, which, as noted above, returns the ID of a specific element of an HTML DOM. It's frequently used for manipulating elements in a document. $() allows for shorter and more efficient JavaScript coding. Traditional method: document.
The function* declaration ( function keyword followed by an asterisk) defines a generator function, which returns a Generator object.
(0, someFunction)
simply returns someFunction
so this is just equivalent to
var someOtherThing = someFunction(oneParameter);
Are you sure you typed it exactly as it was ? If so, and if it wasn't some kind of obfuscation, then it might be the unfortunate result of some minification. If the real code were a little different, for example (0, someObject.someFunction)
, there might be some use of this indirect function call.
EDIT :
You edit confirms that it the goal was probably to ensure that this
, inside the function, is the global object (window
in a browser) and not the object on which Va
was attached (_
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With