I am reading a open source project and it has a js file like this
var pipe = function(source, listeners){
source.onmessage = function onmessage(msg){
//.. do something ..
};
return {
//.. something ...
};
}(nativeWindow || appjs, {});
What does (nativeWindow || appjs )
means where they both are objects ?
Does it mean that this function is called for both of them ?
Or it is merging both of these objects ?
And is this .onmessage
is something standard thing like alert()
or window
? What i mean by standard is that is there something happening behind the scenes in this .onmessage
function or is it just like simple function ?
Thanks
if nativeWindow evaluates to false (e.g. if it's undefined) then appjs is passed in as source; otherwise nativeWindow is passed in as source. The property onmessage of whichever object ispassed in as source is then set to the onmessage function