(ES6) ES6 (2016)

WellKnownSymbols (WN03)

   1:  const alpha = ['a', 'b', 'c'];
   2:  const numeric = [1, 2, 3];
   3:  numeric[Symbol.isConcatSpreadable] = false;  // numeric won't be flattened during concatenation
   4:  let alphaNumeric = alpha.concat(numeric);
   5:  console.log(alphaNumeric); // Output: ['a', 'b', 'c', [1, 2, 3]].  numeric isn't flattened.
   6:  numeric[Symbol.isConcatSpreadable] = true; //numeric array will be spread when concatinated
   7:  alphaNumeric = alpha.concat(numeric);
   8:  console.log(alphaNumeric); // ['a', 'b', 'c', 1, 2, 3];



Symbol.isConcatSpreadable controls if an object is flattened (spread) when used with concat()

[
  'a',
  'b',
  'c',
  [ 1, 2, 3, [Symbol(Symbol.isConcatSpreadable)]: false ]
]
[ 'a', 'b', 'c', 1, 2, 3 ]





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/WN03.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>