はじめに
今回から,
想定している読者は,
今回の連載では執筆開始時点の最新版であるバージョン1.
Prototypeライブラリの構成
名前空間
このライブラリでは,
名前 | 実体 |
---|---|
Prototype | オブジェクト |
Class | オブジェクト |
Abstract | オブジェクト |
Try | オブジェクト |
PeriodicalExecuter | Prototypeライブラリ式クラス |
Template | Prototypeライブラリ式クラス |
$break | 空オブジェクト |
$continue | Error形のインスタンス, |
Enumerable | オブジェクト |
$A | Array. |
$w | 関数オブジェクト |
Hash | コンストラクタとしての関数オブジェクト |
$H | 関数オブジェクト |
ObjectRange | Prototypeライブラリ式クラス |
$R | 関数オブジェクト |
Ajax | オブジェクト |
$ | 関数オブジェクト |
Element | オブジェクト |
Toggle | オブジェクト |
Insertion | オブジェクト |
Selector | Prototypeライブラリ式クラス |
$$ | 関数オブジェクト |
Form | オブジェクト |
Field | オブジェクト。Form. |
$F | 関数オブジェクト。Form. |
Event | オブジェクト |
Position | オブジェクト |
他のライブラリや,
オブジェクト, クラスの使われ方
ライブラリ内では,
- その下に別のオブジェクトを入れるための親名前空間として使う
- Class.
create()を使って Prototypeライブラリ風のクラスとして定義する - Object.
extend()を使って他のクラス, オブジェクトから継承されることを前提とする関数を集める - コードを簡潔に記述する為に短い名前の関数として使う
特に,
コードを追っていく場合は,
既存オブジェクトへの拡張
Prototypeライブラリの特徴の一つとして,
大きくはElementやArray,
これらの追加メソッドは便利なものが多いのですが,
JavaScriptでコード上でプロパティとして追加されたメソッドには,
このことを忘れていると,
var a = new Array;
a.push(100);
a.push(200);
for (var i in a) {
console.log(i);
}
というコードでは,
この場合は,
先頭のコメント, 著作権表示
0001: /* Prototype JavaScript framework, version 1.5.1.1
0002: * (c) 2005-2007 Sam Stephenson
0003: *
0004: * Prototype is freely distributable under the terms of an MIT-style license.
0005: * For details, see the Prototype web site: http://www.prototypejs.org/
0006: *
0007: /*--------------------------------------------------------------------------*/
0008:
7行目まではコメントです。PrototypeライブラリはMITスタイルのライセンスであることが宣言されています。 このライセンスであるおかげで,