Skip to content

Instantly share code, notes, and snippets.

@sounisi5011

sounisi5011/define.ts

Last active Aug 8, 2019
Embed
What would you like to do?
Symbol.asyncIterator polyfill
if(!Symbol.asyncIterator) {
Object.defineProperty(Symbol, 'asyncIterator', {
enumerable: false, // This line is optional
configurable: false, // This line is optional
writable: false, // This line is optional
value: Symbol('Symbol.asyncIterator'),
});
}
const assert = require('assert');
function equal(value, expected) {
assert.strictEqual(value, expected);
}
function truthy(value) {
assert.ok(value);
}
function falsy(value) {
assert.ifError(value);
}
equal(typeof Symbol.asyncIterator, 'symbol');
/* @see https://www.ecma-international.org/ecma-262/9.0/#table-1 */
equal(Symbol.asyncIterator.toString(), 'Symbol(Symbol.asyncIterator)');
falsy(Symbol.keyFor(Symbol.asyncIterator));
const desc = Object.getOwnPropertyDescriptor(Symbol, 'asyncIterator');
truthy(desc);
/* @see https://www.ecma-international.org/ecma-262/9.0/#sec-symbol.asynciterator */
equal(desc.configurable, false);
equal(desc.enumerable, false);
equal(desc.writable, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment