Reversing an Object.entries conversion

Sure, just use .reduce to assign to a new object: const input = { key:’val’, key2:’val2′, key3:’val3′ }; const output = Object.entries(input) .filter(([k, v]) => { return true; // some irrelevant conditions here }) .reduce((accum, [k, v]) => { accum[k] = v; return accum; }, {}); console.log(output); In modern browsers, you can also use Object.fromEntries … Read more

Is it possible to use subresource integrity with ES6 module imports?

From an HTML document, you can use the <link rel=”modulepreload”> element to perform that integrity check, which is unfortunately currently supported only in Blink browsers. // default script import( “https://unpkg.com/redom@3.2.1/dist/redom.es.js” ) .then( module => console.log( ‘from default script:’, typeof module.List ) ) .catch( console.error ); <link rel=”modulepreload” href=”https://unpkg.com/redom@3.2.1/dist/redom.es.js” integrity=”sha384-notthecorrectsha”> <script type=”module”> import { List } … Read more

Why will ES6 WeakMap’s not be enumerable?

Finally found the real answer: http://tc39wiki.calculist.org/es6/weak-map/ A key property of Weak Maps is the inability to enumerate their keys. This is necessary to prevent attackers observing the internal behavior of other systems in the environment which share weakly-mapped objects. Should the number or names of items in the collection be discoverable from the API, even … Read more

Is there any benefit to call Reflect.apply() over Function.prototype.apply() in ECMAScript 2015?

You can compare the definition of Function.prototype.apply and Reflect.apply in the spec. Basically they are equivalent, but there is a difference: if the arguments list is null or undefined, Function.prototype.apply will call the function with no arguments, and Reflect.apply will throw. function func() { return arguments.length; } func.apply(void 0, null); // 0 Reflect.apply(func, void 0, … Read more