TypeScript - Lambda

TypeScript 支援 Lambda 語法,語法如下:

(input parameters) => expression
(input parameters) => {statement;}


寫起來就像下面這樣:

1
2
3
4
var Execute = (cmd: string, ...params: string[]): void =>
alert(cmd + "(" + params.join(", ") + ")");

Execute("Test", "Param1", "Param2");