With the use of labels, a meta variable is a local-scope variable that can adopt object-oriented properties, when needed
Original version
function Apple(){
this.color = 'Red'
this.shape = 'Round'
}
let color = 'Pink'
let myFruit = new Apple() // { color:'Red', shape:'Round' }
myFruit.color = 'Green' // { color:'Green', shape:'Round' }
myFruit.color = color // { color:'Pink', shape:'Round' }
New version
let color = 'Pink'
// A line label + scope
Apple : {
let color = 'Red'
let shape = 'Round'
}
let myFruit = { color:'' }
myFruit.color = Apple.color // 'Red'
myFruit.color = color // 'Pink'
To address the issue of possible memory overhead -- if the ecma specifies an implementation based upon pilot-wave theory (ie compilation in reverse!), all forward references are known and thus a two-pass interpreter is not needed.
It doesn't seem like the original and new version achieve the same thing. What's the advantage of the new version over something like
let color = 'Pink'
// A line label + scope
let Apple = {
color: 'Red',
shape: 'Round'
}
let myFruit = { color:'' }
myFruit.color = Apple.color // 'Red'
myFruit.color = color // 'Pink'