jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.46k stars 102 forks source link

Properties that start with an underscore get prefixed inside classes. #335

Closed andrei-cardonet closed 9 years ago

andrei-cardonet commented 9 years ago

Property names inside classes get prefixed with the class name, even though they are not properties of that class.

input:

class Bad {
    doOddBehaviour(obj) {
        console.log(obj._prefixed + 1)
    }
}

var myBad = new Bad()
myBad.doOddBehaviour({_prefixed: 5})

var myOk = {_prefixed: 5}
console.log(myOk._prefixed)

output (with --harmony option):

function Bad(){"use strict";}
    Object.defineProperty(Bad.prototype,"doOddBehaviour",{writable:true,configurable:true,value:function(obj) {"use strict";
        console.log(obj.$Bad_prefixed + 1) //notice that accessing the property of this object will fail (the output will be 'undefined')
    }});

var myBad = new Bad()
myBad.doOddBehaviour({_prefixed: 5})

var myOk = {_prefixed: 5}
console.log(myOk._prefixed)

When executed, the console output will be:

undefined
5

Expected:

6
5
$ jsx -V
0.13.3
andrei-cardonet commented 9 years ago

Wrong repository. Closing ticket.