typeof
is an operator that, when used on a variable that’s not defined at all, will still result in the value 'undefined'
. So the expression:
(typeof exports === 'undefined' ? window : exports)
checks whether exports
isn’t in scope. If it isn’t, it results in window
(the global object in browsers), and if it is, it results in exports
(a standard name for exporting things from [sort of] modules – see Relation between CommonJS, AMD and RequireJS?). The result is then assigned to root
.
In case you were wondering about the conditional operator,
var d = a ? b : c;
is more or less equivalent to
var d;
if (a) {
d = b;
} else {
d = c;
}
As for root.Retina = Retina;
, like with every other property in JavaScript, there’s no need to declare it and there is no facility to declare it.