I'm playing with some EcmaScript 2015 features and I must say that specification is rather hard to understand.
I totally understand that this code should throw error of some kind:
(function(a = b, b = 1) { })();
And I know that default value could use outer scope:
(function() {
let c = 1;
return (function(a = c) { return a === 1; })();
})();
But I don't understand why these examples are not good:
(function() {
let a = 1;
(function(a = a) { })();
})();
(function() {
let b = 1;
(function(a = b, b = 2) { })();
})();
My Chrome 59.0.3071.115 throws ReferenceError that variable is not defined.
It seems that Chrome is doing some optimization where only 1 scope is created where all parameters set as inaccessible, and they are added one by one after their assignment.
Some proof of this could be:
(function(a = () => b, b = 2) { return a() === 2; })();
This looks like an missing opportunity for my taste and I'm wondering does specification force to use only 1 scope here or this is only v8 implementation details.
Could somebody please point me to place in specification which could clarify this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…