Baseline Widely available
éææ¹æ³ Reflect.apply()
éè¿æå®çåæ°å表åèµ·å¯¹ç®æ (target) 彿°çè°ç¨ã
console.log(Reflect.apply(Math.floor, undefined, [1.75]));
// Expected output: 1
console.log(
Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]),
);
// Expected output: "hello"
console.log(
Reflect.apply(RegExp.prototype.exec, /ab/, ["confabulation"]).index,
);
// Expected output: 4
console.log(Reflect.apply("".charAt, "ponies", [3]));
// Expected output: "i"
è¯æ³
Reflect.apply(target, thisArgument, argumentsList)åæ°
ç®æ 彿°ã
target 彿°è°ç¨æ¶ç»å®ç this 对象ã
target 彿°è°ç¨æ¶ä¼ å ¥çå®åå表ï¼è¯¥åæ°åºè¯¥æ¯ä¸ä¸ªç±»æ°ç»ç对象ã
è¿å弿¯è°ç¨å®å¸¦çæå®åæ°å this
å¼çç»å®ç彿°åè¿åçç»æã
妿 target
对象ä¸å¯è°ç¨ï¼æåº TypeError
ã
è¯¥æ¹æ³ä¸ ES5 ä¸Function.prototype.apply()
æ¹æ³ç±»ä¼¼ï¼è°ç¨ä¸ä¸ªæ¹æ³å¹¶ä¸æ¾å¼å°æå® this
åéååæ°å表 (arguments) ï¼åæ°å表å¯ä»¥æ¯æ°ç»ï¼æç±»ä¼¼æ°ç»ç对象ã
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
ä½¿ç¨ Reflect.apply
æ¹æ³ä¼ä½¿ä»£ç æ´å ç®æ´ææã
Reflect.apply()
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"
è§è æµè§å¨å
¼å®¹æ§ ç¸å
³è¿æ¥
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