Last active
July 28, 2016 15:50
-
-
Save pointwiseproduct/68cf8e9b3610686dc827536e1140ea7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TypeScriptのめんどくさいところ. | |
class A{ | |
value: number; | |
// 引数の型が違うコンストラクタを分けて記述できない. | |
// constructor(){ ... } | |
// constructor(other: A){ ... } | |
// 仕方が兄のでvalue?: anyを列挙してコンストラク内部でinstanceofチェックをする. | |
constructor(_other?: any){ | |
// default constructor. | |
if(_other == null){ | |
this.value = 114514; | |
return; | |
} | |
// copy constructor. | |
if(_other instanceof A){ | |
let other: A = <A>_other; //_otherはAって分かりきってるのに一々キャするの!? | |
this.value = other.value; | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment