by mschuetz · 10y ago · 0 comments
class Vector{
constructor(x = 0, y = 0, z = 0){
this.x = x;
this.y = y;
this.z = z;
setTimeout(function(){
console.log(this.x + ", " + this.y + ", " + this.z);
}.bind(this), 10);
}
};
var v = new Vector(1, 2, 3); // prints 1, 2, 3
Edit:
Ok I can see this be potentially useful for function chaining, I just don't do that very much. class Vector {
constructor(x=0, y=0, z=0) {
this.x = x;
this.y = y;
this.z = z;
setTimeout(() => console.log(this.x + ", " + this.y + ", " + this.z), 10);
}
}