10. 基本的なスクリプト
module Greeting
{
export class Hello
{
private text : string;
constructor(text : string)
{
this.text = text;
}
say() : void
{
console.log(this.text);
}
}
}
var hello : Greeting.Hello = new Greeting.Hello("Hello, World!");
hello.say();
名前空間の指定
class
型の指定
アクセス修飾子
13年7月21日日曜日
11. 基本的なスクリプト
var Greeting;
(function (Greeting) {
var Hello = (function () {
function Hello(text) {
this.text = text;
}
Hello.prototype.say = function () {
console.log(this.text);
};
return Hello;
})();
Greeting.Hello = Hello;
})(Greeting ¦¦ (Greeting = {}));
var hello = new Greeting.Hello("Hello, World!");
hello.say();
13年7月21日日曜日
12. いろいろ
((s) =>
{
alert(s);
})("Hello, World!");
ラムダ式 継承
class Base
{
}
class John extends Base
{
}
ジェネリクス
function head<T>(array:Array<T>): T
{
return array[0];
}
var num: number = head<number>([10, 20, 30]);
var str: string = head(["red", "blue", "yellow"]);
console.log(num);
console.log(str);
13年7月21日日曜日