- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- バックアップ を表示
- JavaScript/OOP/クラスの作り方/オブジェクトリテラルを使ったクラス作成 - 基本 へ行く。
- 1 (2012-07-24 (火) 16:21:15)
* オブジェクトリテラルを使ったクラス作成 - 基本 [#f8623c64] ** オブジェクトリテラルでクラスを定義・インスタンスを生成 [#ec251cfe] var animal = { name : "Taro", say : function () { alert("My name is " + this.name) } }; ** インスタンスの利用 [#r74c84d6] animal.say(); console.log(typeof animal); // => "object" *** オブジェクトリテラルではなくObjectを使うと [#ub7bbb45] ↑では{} を使ってオブジェクトリテラルで簡易に書いているが、↓以下のように書くのと同じ。 var animal = new Object(); animal.name = "Taro"; animal.say = function () { alert("My name is " + this.name) };