Introduce Meta variables

Introduce Meta variables

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'

This:

Apple : {
    let color = 'Red' 
    let shape = 'Round'
}

Is already valid code, so you wouldn't be able to change it's meaning.

3 Likes

Like @rwaldron said, it's like you're labeling a block statement, have you learnt about labeling blocks, for loops and all that?