| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Meta_programming | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
ECMAScript 2015, JavaScript Proxy Reflect, ( , , , ). JavaScript.
ECMAScript 6, Proxy . , :
var handler = {
get: function (target, name) {
return name in target ? target[name] : 42;
},
};
var p = new Proxy({}, handler);
p.a = 1;
console.log(p.a, p.b); // 1, 42
Proxy target ( ) handler - - get. "" , undefined, 42.
Proxy :
- , -.
, . (hooking) .
, Proxy. Proxy . (invariants), .
, invariants. , TypeError.
| / | ||
|---|---|---|
handler.getPrototypeOf()
|
Object.getPrototypeOf()Reflect.getPrototypeOf()__proto__Object.prototype.isPrototypeOf()instanceof
|
|
handler.setPrototypeOf()
|
Object.setPrototypeOf()Reflect.setPrototypeOf()
|
target ,
prototype
Object.getPrototypeOf(target).
|
handler.isExtensible()
|
Object.isExtensible()Reflect.isExtensible()
|
Object.isExtensible(proxy) ,
Object.isExtensible(target).
|
handler.preventExtensions()
|
Object.preventExtensions()Reflect.preventExtensions()
|
Object.preventExtensions(proxy)
true ,
Object.isExtensible(proxy) false.
|
handler.getOwnPropertyDescriptor()
|
Object.getOwnPropertyDescriptor()Reflect.getOwnPropertyDescriptor()
|
|
handler.defineProperty()
|
Object.defineProperty()Reflect.defineProperty()
|
|
handler.has()
|
Property query: foo in proxyInherited property query: foo in Object.create(proxy)Reflect.has()
|
|
handler.get()
|
Property access: proxy[foo]and proxy.barInherited property access: Object.create(proxy)[foo]Reflect.get()
|
|
handler.set()
|
Property assignment: proxy[foo] = bar and
proxy.foo = barInherited property assignment: Object.create(proxy)[foo] = barReflect.set()
|
|
handler.deleteProperty()
|
Property deletion: delete proxy[foo] and
delete proxy.fooReflect.deleteProperty()
|
, , . |
handler.enumerate()
|
Property enumeration / for...in:
for (var name in proxy) {...}Reflect.enumerate()
|
enumerate
.
|
handler.ownKeys()
|
Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.keys()Reflect.ownKeys()
|
|
handler.apply()
|
proxy(..args)Function.prototype.apply() and
Function.prototype.call()Reflect.apply()
|
. |
handler.construct()
|
new proxy(...args)Reflect.construct()
|
Object. |
Proxy Proxy.revocable() Proxy. revoke, -. TypeError.
var revocable = Proxy.revocable(
{},
{
get: function (target, name) {
return "[[" + name + "]]";
},
},
);
var proxy = revocable.proxy;
console.log(proxy.foo); // "[[foo]]"
revocable.revoke();
console.log(proxy.foo); // TypeError
proxy.foo = 1; // TypeError
delete proxy.foo; // TypeError
typeof proxy; // "object", typeof
Reflect , JavaScript. , Proxy. Reflect .
Reflect .
, Reflect.has() in :
Reflect.has(Object, "assign"); // true
apply ES5 Function.prototype.apply() ( this) , ( - ).
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
Reflect.apply(Math.floor, undefined, [1.75]);
// 1;
Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]);
// "hello"
Reflect.apply(RegExp.prototype.exec, /ab/, ["confabulation"]).index;
// 4
Reflect.apply("".charAt, "ponies", [3]);
// "i"
Object.defineProperty, , , TypeError. - try...catch . Reflect.defineProperty, , , if...else :
if (Reflect.defineProperty(target, property, attributes)) {
//
} else {
// -
}
This page was last modified on 29 . 2026 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |