https://developer.mozilla.org/ja/docs/JavaScript/Reference/Operators/instanceof
function C(){};
function D(){};
D.prototype = new C();
var c = new C();
var d = new D();
c instanceof C; //true
d instanceof D; //true
それぞれの優先順位を書かないと
| //!overload | |
| constructor(x: number, y: number) { | |
| this.x = a; | |
| this.y = b; | |
| } | |
| constructor(v: Vector2) { | |
| this.x = v.x; | |
| this.y = v.y; | |
| } |
https://developer.mozilla.org/ja/docs/JavaScript/Reference/Operators/instanceof
function C(){};
function D(){};
D.prototype = new C();
var c = new C();
var d = new D();
c instanceof C; //true
d instanceof D; //true
それぞれの優先順位を書かないと
| constructor(x: number, y: number); | |
| constructor(v: Vector2); | |
| constructor(a: any, b?: number) { | |
| // null, undefined が渡された場合 | |
| if (a == null) { | |
| this.x = 0; | |
| this.y = 0; | |
| return; | |
| } | |
| // instanceof でどちらが呼ばれたのか判断 | |
| if (a instanceof Vector2) { | |
| this.x = a.x; | |
| this.y = a.y; | |
| } else { | |
| this.x = a; | |
| this.y = b; | |
| } | |
| } |