I'm new to JavaScript and since I come from strongly-typed languages I've chosen TypeScript.
I'd like to know what happens to variable red in Red getter in this code. Will it be recreated on every call (like in Green getter) or created once and used every time? Which is best?
class Color {
public R: number;
public G: number;
public B: number;
public A: number;
static get Red(): Color {
var red = new Color(255, 0, 0);
Color.Red = function() { return red; }
return red;
}
static get Green(): Color {
return new Color(0, 255, 0);
}
constructor(red: number, green: number, blue: number, alpha: number = 255) {
this.R = red;
this.G = green;
this.B = blue;
this.A = alpha;
}
}