In JavaScript, I can write:
x = new Object({ a: 3 })
and I will have x = { a: 3 }
Similarly, I can write
x = Object({ a: 3 })
and I will have again x = { a: 3 }.
My question is: how is it implemented Objectto satisfy both of these ways of calling it? In the first case, he will receive a new one this, and in the second he will receive a global object.
My best guess is something like:
var Object = function(obj) {
var global = (function() { return this; })();
if (global == this) {
return { ...obj };
} else {
}
}
source
share