And you can too!
// Sets
var s = new Set();
s.add("hello").add("goodbye").add("hello");
s.size === 2;
s.has("hello") === true;
// Maps
var m = new Map();
m.set("hello", 42);
m.set(s, 34); // <- use an object as a key!
m.get(s) == 34;// Sets
var values = [1, 1, 1, 1, 2], set = {};
values.forEach(addToSet(set));
//...
var testValue = 1;
if (values[testValue]) {
console.log('found ' + testValue);
}
function addToSet(set) {
return function(value) {
set[value] = true;
};
}
// Sets
var s = new Set([1, 1, 1, 1, 2]);
//...
var testValue = 1;
if (s.has(testValue)) {
console.log('found ' + testValue);
}
Inheritable!
Can create custom subclasses with extra behavior. EG: SetSequence type adds .map(), .forEach() etc
function timeout(duration = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
})
}
var p = timeout(1000).then(() => {
return timeout(2000);
}).then(() => {
throw new Error("hmm");
}).catch(err => {
return Promise.all([timeout(100), timeout(200)]);
})Promise.race(iterable)
Promise.reject(reason)
Promise.resolve(value)Number.isNaN('???')
false
isNaN('???')
true[ ]
Object.assign(target, ...sources)
var obj = { a: 1 };
var copy = angular.extend({}, obj);
console.log(copy); // { a: 1 }Copies enumerable and own properties from a source object to a target object. It uses [[Get]] on the source and [[Set]] on the target, so it will invoke getters and setters.
var obj = { a: 1 };
var copy = Object.assign({}, obj);
console.log(copy); // { a: 1 }
//Supports multiple source objects
var a = { a: 1 }, b = { b: 1 }, c = { c: 1};
var merged = Object.assign({}, a, b, c);Object.is(value1, value2)
Almost the same as === with the following exceptions: