假设我在 JavaScript 中有这样的东西:
var obj = { name: "Luis" };
Object.seal( obj );
obj.address = "Fx"; //what should happen here?
那么,正确的行为是什么?它不在严格模式下,所以我假设 obj.address 行将被忽略。但是,情况并非如此,因为它会抛出 Chrome。我正在查看 V8 的测试,它似乎应该只在严格模式下抛出:
object.seal 测试代码: http ://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/object-seal.js?spec=svn7379&r=7379
这是该文件中的一些代码:
Object.seal(obj);
// Make sure we are no longer extensible.
assertFalse(Object.isExtensible(obj));
assertTrue(Object.isSealed(obj));
// We should not be frozen, since we are still able to
// update values.
assertFalse(Object.isFrozen(obj));
// We should not allow new properties to be added.
obj.foo = 42;
assertEquals(obj.foo, undefined);
顺便说一句,有来自严格模式的测试,我的例子会清楚地抛出:http ://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/strict-mode.js?spec =svn7250&r=7250
有任何想法吗?