Flow syntax {| <data> |}
could be used in EcmaScript too to mean Object.freeze({ <data> })
Or maybe called crossRealmnInstanceof
. The objective is to have a way to determine if an object is an instance of a built-in even cross-realmns.
(function () { | |
'use strict'; | |
function mergeClass(receivingClass, givingPrototype) { | |
if (givingPrototype === Object.prototype) { | |
return; | |
} | |
// fetch inherited properties | |
const givingPrototypeProto = Object.getPrototypeOf(givingPrototype); |
(function () { | |
'use strict'; | |
/* | |
Result: | |
========= NEW TEST ========= | |
VM1096:14 Before wrap: <p><strong>Hello</strong> <em>World</em></p> | |
VM1096:19 Wrapping: Hello World | |
VM1096:25 After wrap: <p><section><strong>Hello</strong> <em>World</em></section></p> | |
VM1096:13 ========= NEW TEST ========= |
Flow syntax {| <data> |}
could be used in EcmaScript too to mean Object.freeze({ <data> })
Or maybe called crossRealmnInstanceof
. The objective is to have a way to determine if an object is an instance of a built-in even cross-realmns.
// new RegExp('/test/i') | |
// is interpreted as /\/test\/i/ | |
// this function interprets it as | |
// /test/i | |
function parseRegExp(regExpStr) { | |
if (typeof regExpStr !== 'string') { | |
throw new TypeError('Invalid argument: not a string.'); | |
} | |
const start = regExpStr.indexOf('/'); |
EcmaScript 2015 introduced a new mechanism that enabled developers to define the default values of their function parameters.
Though it is powerful, that mechanism often cannot be used when setting the default values of the properties of received object arguments without destructuring them.
One such case would be a method having to pass the argument to another method :*
class A {
// Remove comments from JSON with this JavaScript RegExp | |
// Only strips out /* */ style comments | |
const stripJsonRegExp = /(?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)\/\*(.|\n)*?\*\/(?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)/gm; | |
// Usage: | |
const commentedJson = String.raw` | |
/* test 1 */ | |
{ /* test2 */ |
The creation process of CSSStyleSheet
s is different in almost all browsers:
const [first, second, ...middle, beforeLast, last] = anIterable;
At any step, if the iterator reaches the end of its available values, stop the algorithm.
middle
to a new empty array.middle
excluded,
I hereby claim:
To claim this, I am signing this object: