-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG : compiler Anonymous class #18515
Comments
Perfect compiler would be
|
Duplicate of #8476 |
@mhegazy This report is not duplicated because the compiler constructs the methods and forgets the attributes |
@renatoprogramer arrays are not automatically initialized |
Especially adding a non-primative to a prototype is not a good thing. ALL instances would share that non-primative instance, unless they initialised it in their constructor: var Carro = (function () {
function Carro() {
}
Carro.prototype.marcas = function () {
return (function () {
function class_1() {
}
class_1.prototype.stars = []; /// COMPILE ADD <---------------------------------------------
class_1.prototype.ford = function (stars) {
this.stars.push(stars);
return this;
};
class_1.prototype.mercedes = function (stars) {
this.stars.push(stars);
return this;
};
return class_1;
}());
};
return Carro;
}());
var a = new Carro();
var marcas = a.marcas();
var ab = new marcas();
ab.ford(3);
ab.mercedes(2);
var ab2 = new marcas();
console.log(ab.stars === ab2.stars); // true!!!! Not good!
console.log(ab.stars); // [3, 2]
console.log(ab2.stars); // [3, 2]!!!!! Not good! As Mohammed says, initialisers are optional (and for good reasons), detecting accessing an uninitialised property would be useful and is tracked by the issue mentioned. |
Is Bug in compiler ?
Output compile:
Error:
Uncaught TypeError: Cannot read property 'push' of undefined at class_1.ford (<anonymous>:9:27) at <anonymous>:4:4
The text was updated successfully, but these errors were encountered: