On 14.04.2011 20:42, David Herman wrote:
Think of it this way: dynamic binding no, dynamic assignment yes.


Yes, I've already learned it testing modules.

Though, should say that it will decrease the beauty JS definitions as runtime expressions. The price? -- interpreter efficiency of course (direct lexical scope mapping of bindings, O(1) for resolving) and early-compile-time errors. But as was said, languages first of all are for humans, not for machines, so in chaise of efficiency we shouldn't turn the language into less convenient for exactly programmers. But, it's just a side phylosopical note ;) Moreover, I also cannot say that dynamic bindings are so often case, so the efficiency of course matters.

So this means, no function expressions depending on the condition? I.e.:

this["foo"] = isDebug ? function () { ... } : function () { ... }
var foo = isDebug ? function() { ... } : function() { ... }


Yeah, right, but not dynamic names anymore.

Or I guess, such cases will be replaced with function statements, right?

if (isDebug) {
     function debug() { ... }
} else {
     function debug() { ... }
}
Sure, that would be fine too.


You said (in the next letter) that it will be a local (like the let- ones) binding. Seems, it will "break" previous semantics. Though, again, today the best practice is to avoid function statements at all, because of difference in implementation; only SpiderMonkey has the sensible one IMO. And in SM's it's a outer scope binding, not the inner.

However, no dynamic function creation anymore (and actually, any binding).
Of course you can still do dynamic function creation. You just can't do dynamic 
binding.


Yes, yes, but which decreases elegance of definitions but increases "intermediate noise" (though, maybe not so noise?).

I just remember nice snippets such as:


     ['Object', 'Array', 'String', 'Function', 'RegExp'].forEach(function 
(constructorName) {
         this['is' + constructorName] = function (object) {
             return Object.prototype.toString.call(object) == '[object ' + 
constructorName + ']';
         };
     });

which allowed me to create several test-function such as "isString", "isArray", 
etc.

Nothing of this anymore in ES6, right?
For the most part, this will not be possible. You can do it in a phased way, by 
creating the globals dynamically via the module loader *before* evaluating the 
script that wants to use them. E.g.:

     ['Object', 'Array', 'String', 'Function', 
'RegExp'].forEach(function(constructorName) {
         ModuleLoader.defineGlobal('is' + constructorName, function(object) {
             return Object.prototype.toString.call(object) == '[object ' + 
constructorName + ']';
         });
     });


Hm, `defineGlobal`? It's interesting.

But these globals won't be accessible to scripts that have already been 
compiled; only to scripts that are subsequently compiled and evaluated, e.g. 
via ModuleLoader.eval.


Which again seems as in chaise of efficiency, let's take away (a little of) convenience from a user.

Anyway, thanks for clarifications, Dave.

Dmitry.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to