开发者

Overwrite Object function didn't affect {} expression?

开发者 https://www.devze.com 2023-03-14 21:07 出处:网络
I overwrite the Object constructor: function Object() { console.log(\"here\"); } when I call var x = new Object();, I can see \"here\".

I overwrite the Object constructor:

function Object() {
    console.log("here");
}

when I call var x = new Object();, I can see "here".

However, when I call var x = {};, I can't got it.

开发者_运维问答Isn't {} the same as new Object()? How can I get this work?


using object() creates new function with name object with scope on document object, actually does not override object. While using var x = {}, it use original JS object.

0

精彩评论

暂无评论...
验证码 换一张
取 消