Baseline Widely available
handler.construct()
ë©ìëë new
ì°ì°ìì ëí í¸ë©ì
ëë¤. ê²°ê³¼ Proxy ê°ì²´ìì new ì°ì°ì´ ì í¨íë ¤ë©´ íë¡ì를 ì´ê¸°ííë ë° ì¬ì©ëë ëì ê°ì²´ ìì²´ì ë´ë¶ [[Construct]]
ë©ìëê° ìì´ì¼ í©ëë¤(ì¦, new target
ì´ ì í¨í´ì¼ í¨).
function monster1(disposition) {
this.disposition = disposition;
}
const handler1 = {
construct(target, args) {
console.log(`Creating a ${target.name}`);
// Expected output: "Creating a monster1"
return new target(...args);
},
};
const proxy1 = new Proxy(monster1, handler1);
console.log(new proxy1("fierce").disposition);
// Expected output: "fierce"
구문
new Proxy(target, {
construct(target, argumentsList, newTarget) {},
});
매ê°ë³ì
ë¤ì 매ê°ë³ìë construct()
ë©ìëì ì ë¬ë©ëë¤. this
ë ì²ë¦¬ê¸°ì ë°ì¸ë©ë©ëë¤.
target
ëì ê°ì²´.
argumentsList
ìì±ìì ì¸ì 목ë¡.
newTarget
ìë í¸ì¶ë ìì±ì. p
ì.
construct
ë©ìëë ë°ëì ê°ì²´ë¥¼ ë°íí©ëë¤.
handler.construct()
ë©ìëë new
ì°ì°ìì ëí í¸ë©ì
ëë¤.
ì´ í¸ë©ì ë¤ì ìì ì ê°ë¡ì± ì ììµëë¤.
new myFunction(...args)
Reflect.construct()
ë¤ì ë¶ë³ ì¡°ê±´ì´ ìë°ëë©´ íë¡ììì TypeError
ê° ë°ìí©ëë¤.
Object
ì¬ì¼ í©ëë¤.ë¤ì ì½ëë new
ì°ì°ì를 í¸ë©í©ëë¤.
const p = new Proxy(function () {}, {
construct(target, argumentsList, newTarget) {
console.log(`called: ${argumentsList}`);
return { value: argumentsList[0] * 10 };
},
});
console.log(new p(1).value); // "í¸ì¶: 1"
// 10
ë¤ì ì½ëë ë¶ë³ ì¡°ê±´ì ìë°í©ëë¤.
const p = new Proxy(function () {}, {
construct(target, argumentsList, newTarget) {
return 1;
},
});
new p(); // TypeError ìì¸ ë°ì
ë¤ì ì½ëë íë¡ì를 ë¶ì ì íê² ì´ê¸°íí©ëë¤. íë¡ì ì´ê¸°íì target
ìì²´ë new
ì°ì°ì ëí ì í¨í ìì±ìì¬ì¼ í©ëë¤.
const p = new Proxy(
{},
{
construct(target, argumentsList, newTarget) {
return {};
},
},
);
new p(); // TypeError is thrown, "p" is not a constructor
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4