构造函数不会影响

构造函数不会影响

本文介绍了覆盖 Array 构造函数不会影响 [],对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚读到:http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx

I just read this: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx

我的印象是覆盖 ObjectArray 仅在您选择使用时才有效创建数组/对象时的构造函数,但是,根据那篇文章,它也对文字创建({}[])...

I was under the impression that overwriting Object or Array only had an effect if you chose to use the constructor functions when creating arrays/objects, but, according to that article, it also has an effect on literal creation ({} and [])...

我的逻辑:

Array = function(){ alert('Hi'); };

[1,2,3,4,5];
([1,2,3,4,5]);
var a = [1,2,3,4,5];

// ...
// ... Nothing is alerted

那么,我是疯了还是有一些我不知道的特定于实现的怪癖?

So, am I going crazy or are there some implementation-specific quirks I'm not aware of?

推荐答案

据我所知,这是 ECMAScript 规范的一个问题,一年多前在所有主要浏览器中都得到了修复.这里是一个链接,可将您链接到最相关的链接;)

As far as I know this is an issue with the ECMAScript specification and was fixed in all major browsers over a year ago. Here is a link that links you to the most relevant links ;)

但要真正回答您的问题,是的,ObjectArray 构造函数也被调用以进行文字创建.实施的修复浏览器只是使这些(和其他)保持不变,因此它们不能被自定义脚本覆盖.

But to actually answer your question, yes, the Object and Array constructors are also invoked for literal creations. The fix browsers implemented just made these (and others) constant so they can't be overridden by custom scripts.

这篇关于覆盖 Array 构造函数不会影响 [],对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:05