This essay explains how the ES6 Realm API makes it possible to create robust language abstractions that allow hooking into the behavior of eval
, and how this can be used to implement different dialects of JavaScript.
Imagine we want to add Doug Crockford's ??
operator, which acts like a short-circuiting logical OR operator, except instead of checking truthiness, it returns the first argument's value if the first argument is any value other than undefined
.
Since it makes everything simpler and cleaner, I'm going to assume I can use do
-expressions for the implementation. (They're looking good for ES7!) So with that said, when we "crockpile" EXPR1 ?? EXPR2
we