ページへ戻る
− Links
印刷
TypeScriptの関数
の編集 ::
NJF Wiki
xpwiki
:
TypeScriptの関数
の編集
# da6d0324 の編集
ページ内容:
*オーバーライド [#da6d0324] 関数の定義を並べると変数や戻り値の型や個数を変えるオーバーライドも可能。 function testFunc(x:number):number; function testFunc(x:string):string; function testFunc(x:number,y:number):number; function testFunc(x:any,y:number = 1):any{ if(typeof x == "number"){ return x + y; }else if(typeof x == "string"){ return "string:" + x; } } console.log(testFunc(2)); // => 3 console.log(testFunc(2,4)); // => 6 console.log(testFunc("test")); // => "string:test" testFunc(true); // => エラー
編集の要約:
Q & A 認証:
ページ更新時は次の質問にお答えください。(プレビュー時は必要ありません)
Q:
「名古屋」の読みがな?(ひらがなで)
A:
お名前:
タイムスタンプを変更しない
テキスト整形のルールを表示する
[1]
Links list
(This host) = https://njf.jp
(This host)
/cms/modules/xpwiki/?cmd=edit&help=true&page=TypeScript%E3%81%AE%E9%96%A2%E6%95%B0