From 0d58e714ce0c36227c971c4000886060b10cd7d4 Mon Sep 17 00:00:00 2001 From: new9xgh <244013304@qq.com> Date: Wed, 21 Nov 2018 11:09:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E5=AE=8C=E5=96=84=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=80=82=202.preventExtensions=E4=BB=8B?= =?UTF-8?q?=E7=BB=8D=E4=B8=AD=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8E=E6=8F=8F=E8=BF=B0=E6=89=80=E7=94=A8=E7=9A=84=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E3=80=82=203.preventExtensions=E4=BB=8B=E7=BB=8D?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=EF=BC=9AObject.preventExtensions()=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=E8=BE=93=E5=87=BA=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E3=80=82=204.=E4=BF=AE=E6=94=B9=E2=80=9C=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=98=AF=E4=B8=8D=E5=8F=AF=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E2=80=9D=E6=8B=AC=E5=8F=B7=E7=9B=B8=E5=85=B3=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=B8=ADnon-extensible=20=E4=B8=8E=20extensible=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/proxy.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/proxy.md b/docs/proxy.md index 8064e63..a0de903 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -642,6 +642,7 @@ var p = new Proxy(function() {}, { }); new p() // 报错 +// Uncaught TypeError: 'construct' on proxy: trap returned non-object ('1') ``` ### deleteProperty() @@ -689,7 +690,7 @@ proxy.foo = 'bar' // 不会生效 上面代码中,`defineProperty`方法返回`false`,导致添加新属性总是无效。 -注意,如果目标对象不可扩展(extensible),则`defineProperty`不能增加目标对象上不存在的属性,否则会报错。另外,如果目标对象的某个属性不可写(writable)或不可配置(configurable),则`defineProperty`方法不得改变这两个设置。 +注意,如果目标对象不可扩展(non-extensible),则`defineProperty`不能增加目标对象上不存在的属性,否则会报错。另外,如果目标对象的某个属性不可写(writable)或不可配置(configurable),则`defineProperty`方法不得改变这两个设置。 ### getOwnPropertyDescriptor() @@ -740,7 +741,7 @@ Object.getPrototypeOf(p) === proto // true 上面代码中,`getPrototypeOf`方法拦截`Object.getPrototypeOf()`,返回`proto`对象。 -注意,`getPrototypeOf`方法的返回值必须是对象或者`null`,否则报错。另外,如果目标对象不可扩展(extensible), `getPrototypeOf`方法必须返回目标对象的原型对象。 +注意,`getPrototypeOf`方法的返回值必须是对象或者`null`,否则报错。另外,如果目标对象不可扩展(non-extensible), `getPrototypeOf`方法必须返回目标对象的原型对象。 ### isExtensible() @@ -778,7 +779,8 @@ var p = new Proxy({}, { } }); -Object.isExtensible(p) // 报错 +Object.isExtensible(p) +// Uncaught TypeError: 'isExtensible' on proxy: trap result does not reflect extensibility of proxy target (which is 'true') ``` ### ownKeys() @@ -967,13 +969,14 @@ Object.getOwnPropertyNames(p) 这个方法有一个限制,只有目标对象不可扩展时(即`Object.isExtensible(proxy)`为`false`),`proxy.preventExtensions`才能返回`true`,否则会报错。 ```javascript -var p = new Proxy({}, { +var proxy = new Proxy({}, { preventExtensions: function(target) { return true; } }); -Object.preventExtensions(p) // 报错 +Object.preventExtensions(proxy) +// Uncaught TypeError: 'preventExtensions' on proxy: trap returned truish but the proxy target is extensible ``` 上面代码中,`proxy.preventExtensions`方法返回`true`,但这时`Object.isExtensible(proxy)`会返回`true`,因此报错。 @@ -981,7 +984,7 @@ Object.preventExtensions(p) // 报错 为了防止出现这个问题,通常要在`proxy.preventExtensions`方法里面,调用一次`Object.preventExtensions`。 ```javascript -var p = new Proxy({}, { +var proxy = new Proxy({}, { preventExtensions: function(target) { console.log('called'); Object.preventExtensions(target); @@ -989,9 +992,9 @@ var p = new Proxy({}, { } }); -Object.preventExtensions(p) +Object.preventExtensions(proxy) // "called" -// true +// Proxy {} ``` ### setPrototypeOf() @@ -1015,7 +1018,7 @@ Object.setPrototypeOf(proxy, proto); 上面代码中,只要修改`target`的原型对象,就会报错。 -注意,该方法只能返回布尔值,否则会被自动转为布尔值。另外,如果目标对象不可扩展(extensible),`setPrototypeOf`方法不得改变目标对象的原型。 +注意,该方法只能返回布尔值,否则会被自动转为布尔值。另外,如果目标对象不可扩展(non-extensible),`setPrototypeOf`方法不得改变目标对象的原型。 ## Proxy.revocable() From 1747317cac0fccb4f43245d669ae13a81153ec28 Mon Sep 17 00:00:00 2001 From: new9xgh <244013304@qq.com> Date: Wed, 21 Nov 2018 11:20:48 +0800 Subject: [PATCH 2/2] fix the word --- docs/proxy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/proxy.md b/docs/proxy.md index a0de903..a9b1d4d 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -941,7 +941,7 @@ Object.getOwnPropertyNames(p) 上面代码中,`obj`对象的`a`属性是不可配置的,这时`ownKeys`方法返回的数组之中,必须包含`a`,否则会报错。 -另外,如果目标对象是不可扩展的(non-extensition),这时`ownKeys`方法返回的数组之中,必须包含原对象的所有属性,且不能包含多余的属性,否则报错。 +另外,如果目标对象是不可扩展的(non-extensible),这时`ownKeys`方法返回的数组之中,必须包含原对象的所有属性,且不能包含多余的属性,否则报错。 ```javascript var obj = {