Baseline Widely available
Symbol.match
ã¯éçãã¼ã¿ããããã£ã§ãã¦ã§ã«ãã¦ã³ã·ã³ãã«ã§ãã Symbol.match
ã表ãã¾ããString.prototype.match()
ã¡ã½ããã¯ç¬¬ 1 弿°ã«å¯¾ãã¦ãå
¥åæååã¨ç¾å¨ã®ãªãã¸ã§ã¯ãã¨ã®ç
§åã«ä½¿ãããã¡ã½ãããããã®ã·ã³ãã«ã§æ¢ãã¾ãããã®ã·ã³ãã«ã¯ããªãã¸ã§ã¯ããæ£è¦è¡¨ç¾ã¨ãã¦æ±ãããã¹ããã©ãããæ±ºå®ããããã«ã使ç¨ããã¾ãã
詳ããã¯ãRegExp.prototype[Symbol.match]()
ããã³ String.prototype.match()
ãåç
§ãã¦ãã ããã
const regexp1 = /foo/;
// console.log('/foo/'.startsWith(regexp1));
// Expected output (Chrome): Error: First argument to String.prototype.startsWith must not be a regular expression
// Expected output (Firefox): Error: Invalid type: first can't be a Regular Expression
// Expected output (Safari): Error: Argument to String.prototype.startsWith cannot be a RegExp
regexp1[Symbol.match] = false;
console.log("/foo/".startsWith(regexp1));
// Expected output: true
console.log("/baz/".endsWith(regexp1));
// Expected output: false
å¤
ã¦ã§ã«ãã¦ã³ã·ã³ãã« Symbol.match
ã§ãã
ãã®é¢æ°ã¯ããªãã¸ã§ã¯ããæ£è¦è¡¨ç¾ã®åä½ããããã©ãããèå¥ããããã«ã使ç¨ããã¾ãããã¨ãã°ãString.prototype.startsWith()
, String.prototype.endsWith()
, String.prototype.includes()
ã¡ã½ããã¯ãæåã®å¼æ°ãæ£è¦è¡¨ç¾ã§ãããã©ããã確èªããæ£è¦è¡¨ç¾ã§ããå ´å㯠TypeError
ãçºçãã¾ããããã§ãmatch
ã·ã³ãã«ã false
ï¼ã¾ãã¯å½å¤ããã ã undefined
ã§ãªããã®ï¼ã«è¨å®ããã¦ããå ´åããã®ãªãã¸ã§ã¯ããæ£è¦è¡¨ç¾ãªãã¸ã§ã¯ãã¨ãã¦ä½¿ç¨ããããã¨ãæå³ãã¦ããªããã¨ã示ãã¾ãã
isRegExp
ãã§ãã¯ãç¡å¹ã«ãã
以ä¸ã®ã³ã¼ã㯠TypeError
ãæãã¾ãã
"/bar/".startsWith(/bar/);
// TypeError ãçºçã/bar/ ãæ£è¦è¡¨ç¾ã§ããã
// Symbol.match ã夿´ããã¦ããªãããã
ãã ããSymbol.match
ã false
ã«è¨å®ããã¨ããªãã¸ã§ã¯ããæ£è¦è¡¨ç¾ãªãã¸ã§ã¯ãã§ã¯ãªããã¨ã示ãã¾ããçµæã¨ãã¦ãstartsWith
㨠endsWith
ã¡ã½ããã¯ãTypeError
ãçºçããã¾ããã
const re = /foo/;
re[Symbol.match] = false;
"/foo/".startsWith(re); // true
"/baz/".endsWith(re); // false
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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