Created
October 23, 2013 07:35
-
-
Save phi-jp/7114084 to your computer and use it in GitHub Desktop.
[tmlib.js] tmlib.js におけるクラス定義 ref: http://qiita.com/phi/items/04c4fae5a9a86dc4afc5
This file contains hidden or 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
tm.define(クラス名, { | |
superClass: 継承元となるクラス名(省略可) | |
// 初期化処理 | |
init: function() { | |
superInit(); // 継承もとの初期化 | |
// TODO: 処理を書いていく | |
} | |
}); |
This file contains hidden or 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
var hoge = クラス名(); |
This file contains hidden or 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
// food 名前空間に Fruit クラスを定義 | |
tm.define("food.Fruit", { | |
price: 0, // メンバ変数 | |
init: function(price) { | |
this.price = price; | |
}, | |
// メンバ関数 | |
getPrice: function() { | |
return this.price; | |
} | |
}); | |
// food 名前空間に Fruit を継承した Apple クラスを定義 | |
tm.define("food.Apple", { | |
superClass: "food.Fruit", | |
init: function() { | |
this.superInit(100); // 親の初期化を呼ぶ | |
} | |
}); | |
// メイン処理 | |
tm.main(function() { | |
// apple クラスを生成(tmlib では new は省略可) | |
var apple = food.Apple(); | |
// 値段を表示 | |
document.write(apple.getPrice()); // 100 と表示される | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment