Ts Day2

2016-06-20  本文已影响0人  helloca

安装tsc-typescript compiler

//只有以sudo权限去执行才能全局安装-g
sudo npm install -g  typescript

tsc的简单使用

#!/usr/local/bin/node
console.log('hello world');
tsc main.ts
node main.js

Function 方法

跟as3的很像,看下文档就知道了。

let suits = ["hearts", "spades", "clubs", "diamonds"];
function pickCard(x:{suit:string;card:number}[]):number;
function pickCard(x:number):{suit:string;card:number};
function pickCard(x):any
  if(typeof x == 'object'){
    let pickcard = Math.floor(Math.random() * x.length);
    return pickcard;
   }else if(typeof x == 'number'){
    let picksuit = Math.floor(x/13);
    return {suit:suits[picksuit],card:x%13};
   }
}
上一篇 下一篇

猜你喜欢

热点阅读