JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9712290
  • Score
    100M100P100Q229213F
  • License MIT

ECMAScript6 Symbol polyfill

Package Exports

  • es6-symbol
  • es6-symbol/implement
  • es6-symbol/is-symbol
  • es6-symbol/polyfill

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (es6-symbol) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

es6-symbol

ECMAScript6 Symbol polyfill

Limitations

  • Underneath it uses real string property names which can easily be retrieved (however accidental collision with other property names is unlikely)
  • As it needs custom toString behavior to work properly. Original Symbol.prototype.toString couldn't be implemented as specified, still it's accessible as Symbol.prototoype.properToString

Usage

If you want to make sure your environment implements Symbol, do:

require('es6-symbol/implement');

If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing Symbol on global scope, do:

var Symbol = require('es6-symbol');

If you strictly want to use polyfill even if native Symbol exists (hard to find a good reason for that), do:

var Symbol = require('es6-symbol/polyfill');

API

Best is to refer to specification. Still if you want quick look, follow examples:

var Symbol = require('es6-symbol');

var symbol = Symbol('My custom symbol');
var x = {};

x[symbol] = 'foo';
console.log(x[symbol]); 'foo'

// Detect iterable:
var iterator, result;
if (possiblyIterable[Symbol.iterator]) {
  iterator = possiblyIterable[Symbol.iterator]();
  result = iterator.next();
  while(!result.done) {
    console.log(result.value);
    result = iterator.next();
  }
}

Installation

NPM

In your project path:

$ npm install es6-symbol
Browser

You can easily bundle es6-symbol for browser with modules-webmake

Tests Build Status

$ npm test