(ES6) ES6 (2016)

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:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/WN05.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>