es6-symbol
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -12,3 +12,2 @@ 'use strict'; | ||
if (typeof Symbol.isConcatSpreadable !== 'object') return false; | ||
if (typeof Symbol.isRegExp !== 'object') return false; | ||
if (typeof Symbol.iterator !== 'object') return false; | ||
@@ -15,0 +14,0 @@ if (typeof Symbol.toPrimitive !== 'object') return false; |
{ | ||
"name": "es6-symbol", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "ECMAScript6 Symbol polyfill", | ||
@@ -5,0 +5,0 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", |
'use strict'; | ||
var d = require('d') | ||
var d = require('d') | ||
, validateSymbol = require('./validate-symbol') | ||
, create = Object.create, defineProperties = Object.defineProperties | ||
, defineProperty = Object.defineProperty, objPrototype = Object.prototype | ||
, Symbol, HiddenSymbol; | ||
, Symbol, HiddenSymbol, globalSymbols = create(null); | ||
@@ -39,7 +40,19 @@ var generateName = (function () { | ||
defineProperties(Symbol, { | ||
create: d('', Symbol('create')), | ||
for: d(function (key) { | ||
if (globalSymbols[key]) return globalSymbols[key]; | ||
return (globalSymbols[key] = Symbol(String(key))); | ||
}), | ||
keyFor: d(function (s) { | ||
var key; | ||
validateSymbol(s); | ||
for (key in globalSymbols) if (globalSymbols[key] === s) return key; | ||
}), | ||
hasInstance: d('', Symbol('hasInstance')), | ||
isConcatSpreadable: d('', Symbol('isConcatSpreadable')), | ||
isRegExp: d('', Symbol('isRegExp')), | ||
iterator: d('', Symbol('iterator')), | ||
match: d('', Symbol('match')), | ||
replace: d('', Symbol('replace')), | ||
search: d('', Symbol('search')), | ||
species: d('', Symbol('species')), | ||
split: d('', Symbol('split')), | ||
toPrimitive: d('', Symbol('toPrimitive')), | ||
@@ -46,0 +59,0 @@ toStringTag: d('', Symbol('toStringTag')), |
# es6-symbol | ||
## ECMAScript6 Symbol polyfill | ||
## ECMAScript 6 Symbol polyfill | ||
For more information about symbols see following links | ||
- [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html) | ||
- [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) | ||
- [Specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-constructor) | ||
### 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` | ||
Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely. | ||
### Usage | ||
If you want to make sure your environment implements `Symbol`, do: | ||
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: | ||
```javascript | ||
require('es6-symbol/implement'); | ||
var Symbol = require('es6-symbol'); | ||
``` | ||
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: | ||
If you want to make sure your environment implements `Symbol`, do: | ||
```javascript | ||
var Symbol = require('es6-symbol'); | ||
require('es6-symbol/implement'); | ||
``` | ||
@@ -63,3 +67,3 @@ | ||
You can easily bundle _es6-symbol_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake) | ||
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/) | ||
@@ -66,0 +70,0 @@ ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-symbol.png)](https://travis-ci.org/medikoo/es6-symbol) |
@@ -23,2 +23,6 @@ 'use strict'; | ||
value: 'foo', writable: true }); | ||
symbol = T.for('marko'); | ||
a(isSymbol(symbol), true); | ||
a(T.for('marko'), symbol); | ||
a(T.keyFor(symbol), 'marko'); | ||
}; |
Sorry, the diff of this file is not supported yet
11917
186
72
21