WellKnownSymbols (WN05)
1: const regex = /Java/g;
2: regex[Symbol.match] = false; // Now string.match(regex) treats it not as a regular expression
3: const str = 'JavaScript and Java';
4: console.log(str.match(regex)); // simple string matching
5: // Expected output: Array ["Java"]
6:
Symbol.match customizes the behavior of String.prototype.match(). If set to false, it treats the value not as a regular expression. [ 'Java', 'Java' ] OR console.log(str.match(regex)); // simple string matching ^ TypeError: 'false' returned for property 'Symbol(Symbol.match)' of object '[object RegExp]' is not a function
WellKnownSymbols context:
ES6 context:
- (2024) Notes about JS Closures. #ES6
- (2024) Notes about Javascript asynchronous programming. #ES6
- (2022) Modern Javascript books #ES6 #Doc
- (2021) JS learning start point #ES6
- (2021) Maximilian Schwarzmüller Javascript lecture #ES6
- (2021) Javascript interview question from Happy Rawat #ES6
- (2021) Javascript tests #ES6
- (2016) New unique features of Javascript (updated). #ES6
Comments (
)

Link to this page:
http://www.vb-net.com/JavascriptES6/WN05.htm
|