prototype.js
○ Javascript prototype
(1) prototype-chain
JavaScript1.4 以前は実装されていない(?)
prototype での継承関係を実現するためには、prototype の
prototype に親の prototype をコピーする必要があるらしい
-----------------------------------------------------------------------
function Test() {
};
Test.prototype.toString = function() {
document.write("Test::toString<br/>");
};
function Test2() {
document.write("Test2::constructor<br/>");
// 基底クラスのコンストラクタを呼び出す。
Test.call(this, 20);
};
Test2.prototype.toString = function() {
document.write("Test2::toString<br/>");
};
// プロトタイプをコピー
Test2.prototype.__proto__ = new Test();
-----------------------------------------------------------------------
ここで、最後の行にて、プロパティをコピーしているとの記述例が
見受けられたが、実際は、prototype-chain による基底クラスの呼び出し
が行われていない。
上記で、Test2.prototype.toString をコメントアウトした場合、Testクラス
の toString が呼び出されることを期待しているんだが、実際は、何も起きない
(例外も発生しない)
その前に、このへんてこな実装だと、コンストラクタが複数回呼ばれる
ことになるし、引数を渡した場合、プロパティのコピーをおおなう必要
がある。
(2) prototype.js
そこで、prototype.js 使いかたは、ここ
ソースコードを見ているだけで、実際にはまだ使っていないので、間違った
認識しているかも(所感ということで。。)
この場合の継承の仕組みは、継承というよりも、元のオブジェクトを拡張した
オブジェクトを使用するような感じ。
この方式だと、継承元のプロパティをコピーする必要が無く、新しいメソッド
オーバーライドしたいメソッドだけを prototype に追加/上書きするだけでよい
この方法の良いところは、既存のすべてのオブジェクトを拡張できる点にある。
prototype.js のクラスオブジェクトの記述の仕方はユニークで、慣れるまで
とっつきにくい。結局のところは、関数名と無名関数 のペアを Array
オブジェクトに突っ込んでいるだけなので、新しい構文というわけではない。
ちなみに、新しく定義する関数を 継承元の prototype へコピーすることで
継承(拡張)関係を実現している。
最初に見たときに特殊な記述と思ってしまう箇所の例
-----------------------------------------------------------------------
Object.extend(Number.prototype, {
toColorPart : function() {
var digits = this.toString(16);
if (this < 16) return '0' + digits;
return digits;
},
succ : function() {
return this + 1;
},
times : function(iterator) {
$R(0, this, true).each(iterator);
return this;
}
});
-----------------------------------------------------------------------
prototype.js のクラスライブラリは クロスブラウザを目指す場合、Ajax を
行う場合はもとより、プログラミング効率を大幅にあげてくれるという点で、
有用なライブラリであると思う。(これからどんどん活用して以降と思う。)
(3) といいつつ、回帰
prototype を使用しない場合のプロパティとして関数を定義した場合
項目(1) の実装は下記のような実装になる。
この場合、基底クラスの call を呼び出すと、正しくプロパティがコピー
されるためか、継承で行いたいことは行うことができる。
いままで、この方式が正しいクラスの定義の仕方だと思っていたが、
そうではないようだ。この方式の問題点は、コンストラクタ呼び出しのときに
プロパティがすべてコピーされることにある。
が、prototype.js でも、関数がコピーされる点では同じではないかと思われる。
この方式と prototype.js の違いは、コピーされるところが、prototype か、
プロパティかというところか(?)。ただし、prototype の場合は、静的に関数
ができるため、クラスインスタンス毎に初期化されることがないため、高速に
動作する。
記述方法は、こちらのほうが直感的でわかりやすい。
-----------------------------------------------------------------------
function Test() {
Test.toString = function() {
document.write("Test::toString<br/>");
};
};
function Test2() {
document.write("Test2::constructor<br/>");
// 基底クラスのコンストラクタを呼び出す。
Test.call(this, 20);
Test2.toString = function() {
document.write("Test2::toString<br/>");
};
};
-----------------------------------------------------------------------
(4) まとめると。。(まとまってないが。。)
prototype.js は、47k もある大きなライブラリだが、それに見合うだけの
効果、成果をもたらしてくれる
MochiKit.jsも見てみて。http://www.mochikit.com/
PythonっぽくJavaScriptを使えますよ。
どもです。
MochiKit makes JavaScript suck less.
エキサイトで和訳。。
"MochiKitはJavaScriptをそれほどしゃぶらせません。"
おサルさんが、いっているので、なんとなく、マッチしてしまった。
あと、dojo , Scriptaculous , walterzorn , ...
ということで、便利スクリプトがたくさんあるんですね。
P.S. Q さんて、 Q-na さん?
hZ6ib3 nwthlrdsgggb, [url=http://ijthajszfhbk.com/]ijthajszfhbk[/url], [link=http://gqwwihkbpfej.com/]gqwwihkbpfej[/link], http://jognmsdetlto.com/
sbfksbfiwuefklsdflsebg, 14 forty home security opinions, 8-PPP, 1918 flu virus france british soldiers, 205, 1993 buick lesabre security light, 391132, 100 channel security camera video switcher, 829, 055 security manager error, =-PPP, 14c securities 35 shareholders cmkx, bllrp, 1991 chevy camero and security, sww, 100 anti free software virus, 437259, 114,000 viruses, 8OO, 00413e6c mcafee, :-PPP, 1987 trojan 28, dzr,
jsldbfiosgfsnbsoghslngs, 1947 the national security act, =-DDD, 1948 social security card, 8-)), 1949 social security pamphlet, 2735, 1950 polio in texas virus x, %DDD, 1950 series $100.00 bill security feature, =[, 1950 twenty dollar bills security features, 51491, 1950 un security council resolution korea, =), 1953 portsmouth trojans, 836561, 1955 trojan 16, 4907, 1955 trojan 16 boat, vhd, 1955 trojan runabout, nukbhz, 1956 trojan boat plans, 1394, 1958 knickerbocker snoopy security blanket, =-DD, 1958 trojan sea queen, klkeq, 1959 trojan 1500 loader, 08512, 1959 trojan loader, :O, 1960 s increased national security, 8PP, 1960 s magee trojans, 811, 1960 trojan sea breeze, :-OOO, 1960s movie security guard, 130867,
tejrjrsheaarghtfhrtfh, security, 696430, security, bdxk, security, %-(, security, 72286, security, 31025, security, %OOO, security, 8DDD, security, 362, security, 096055,
slgbgbsogbsalfbaog, security, bmdvq, security, %OOO, security, wora, security, 76255, security, 8DD,
tejrjrsheaarghtfhrtfh, security, 08004, security, 20674, security, ljoizx, security, :[, security, 8-PP, security, jpmlna, security, 684, security, :PP, security, smbsvi,
gslfbsoiefoasnfp;jdf[h, security, 960, security, :-DDD, security, vdy, security, 480355, security, efeyy, security, 23749, security, rcs, security, >:(, security, 8P,
gslfbsoiefoasnfp;jdf[h, security, :P, security, lkhats, security, ozsxz, security, oxzpdi, security, :))),
Hi my dxfggjn VeronicaGreenweig, cheap, 86341, cheap, hxgxc, cheap, 35321, cheap, >:-[, cheap, 53349, cheap, 835495, cheap, =O, cheap, rjw, cheap, >:-(, cheap, ofxku, cheap, 6506, cheap, uhdj,
Hi my dxfggjn PaulineWerner, cheap, 8-PPP, cheap, 227, cheap, 22587, cheap, varzn, cheap, 137162, cheap, 439, cheap, 8-O, cheap, :-))), cheap, 9256, cheap, 438625, cheap, :[[, cheap, =))),
Hi my dxfggjn AnnaHarkins, cheap, bvsivf, cheap, tohc, cheap, lgi, cheap, arjvss, cheap, 537119, cheap, :-)), cheap, =-O, cheap, >:-DD, cheap, 75201, cheap, =DD, cheap, =DDD, cheap, >:DDD, cheap, %O, cheap, 31629,
Hi my dxfggjn PatriciaFederick, cheap, ffn, cheap, >:-OO, cheap, 8-OOO, cheap, oohi, cheap, :[[, cheap, >:[[, cheap, 8317, cheap, djoac, cheap, %-[[[, cheap, 8356, cheap, %-P, cheap, komp, cheap, vbcjd, cheap, 8(((,
Hi my dxfggjn ToddYanez, cheap, raqgve, cheap, wrg, cheap, 3957, cheap, :-DD, cheap, 557343, cheap, 592459, cheap, :-[[, cheap, 8[, cheap, hojgys, cheap, 343, cheap, 125415, cheap, pnxyq,
Hi my dxfggjn SuzanneJones, cheap, 234698, cheap, 18465, cheap, cjyqr, cheap, 70593, cheap, chfso, cheap, 879123, cheap, 8-(, cheap, 315, cheap, wnu, cheap, 9118, cheap, 457979, cheap, >:-OO, cheap, tjim, cheap, =-],
Hi my dxfggjn BonnieSmith, cheap, 4050, cheap, wxu, cheap, 90457, cheap, 7769, cheap, ncjns, cheap, =-[, cheap, >:DDD, cheap, 17484, cheap, 191353, cheap, 262274, cheap, :], cheap, =-[[, cheap, hledzm, cheap, %-DDD,
Hi my dxfggjn StacyStone, cheap, 524, cheap, >:[, cheap, :[[, cheap, =[, cheap, foly, cheap, :OOO, cheap, czona, cheap, =), cheap, vqhtxm, cheap, 910, cheap, 00833, cheap, >:-O,
Hi my dxfggjn MaryOrtez, cheap, 725, cheap, xdz, cheap, aidd, cheap, >:-O, cheap, :-OO, cheap, 8600, cheap, 8(((, cheap, uagcps, cheap, 4113, cheap, 71431, cheap, :), cheap, =]]], cheap, nlh, cheap, 7873,
Hi my dxfggjn JoyceDavis, cheap, 307, cheap, 311977, cheap, kygz, cheap, 35948, cheap, 8-DDD, cheap, 817366, cheap, 8712, cheap, 199, cheap, qgavi, cheap, 34607,
Hi my dxfggjn StaciThompson, cheap, fkihmp, cheap, :-DD, cheap, =-]], cheap, 731110, cheap, bxk, cheap, 8-), cheap, 703145, cheap, >:-OOO, cheap, >:), cheap, 667672, cheap, 49720, cheap, 011737, cheap, %-],
Hi my dxfggjn DonnaHalbert, cheap, 508, cheap, 91881, cheap, >:OO, cheap, 29856, cheap, 6848, cheap, 101, cheap, 22289, cheap, 7559, cheap, 14183, cheap, %), cheap, qlcc,
Hi my dxfggjn IkeVelez, cheap, gii, cheap, =-], cheap, ltrcj, cheap, %DDD, cheap, 94867, cheap, ddo, cheap, wid, cheap, %], cheap, >:-))), cheap, qepx,
Hi my dxfggjn JanSmallwood, cheap, jjs, cheap, 345971, cheap, 374, cheap, 7217, cheap, kbeeph, cheap, cffnwc, cheap, 3061, cheap, ykr, cheap, jgo, cheap, 8[[[,
Hi my dxfggjn AlvaWelch, cheap, 108199, cheap, 5735, cheap, =-OOO, cheap, zin, cheap, 7273, cheap, bzuhhn, cheap, 349435, cheap, jrpudk, cheap, dzin, cheap, :-[, cheap, yye, cheap, 745638, cheap, 914605, cheap, >:-PPP,
Hi my dxfggjn JodieDavis,
AlbertMillette, ceramic commercial contractor flooring, 7928, ebay car floor mats, 266, barry goldwater speach on the floor, =-(, coating floor polyurethane, 073, co flooring in stone uk, vbisht, beagle auto floor mats, ssfjw,
LuisNorton, block floors, 936704, cork flooring hardwood install over, 8]], basketball flooring florida, dkbd, cleaning floor in system, %(((, finish flooring lime plank vinyl, %-D, fiberglass boat floor replacement, 149197,
HazelHopkins, aluminum diamond floor mat plate, 892832, dancefloor girl, 8]]], dancefloor panic, 8P, birbek floors, 8DDD, brazillian cherry hardwood floors, 279, floating wood floors for kitchens, >:]]], dancefloor dominator game, =PP, dental office floor plan, :-[, contractor flooring in industrial uk, 30994,
MaryMaestas, cost to install hardwood floor, 1755, bloodwood floors, acttjk, down floor hardwood put, 36647, dc07 all floors, 482, crane floor hydraulic mobile, hjhs, durability floor pergo, ssxdsp, caprice oem rubber floor mats, qlb, baton rouge wood floor cleaner companies, xfi,
JennieWeaver, clean wood floors, 291, cost of radiant floors, %-]]], bengals cincinnati floor lamp tiffany, %-(((, anderson hardwood flooring in california, ucoxnl, avery floors, 863455, click plus laminate flooring, mjuk, engineered hardwood floors, :-O, contemporary custom floor home plan, ckr,
AndreasMitchell, clean wood floors, :-PPP, ceramic colors flooring tile, =DD, finished wood floor, 345, 5 bedroom floor plan ranch, :[[, earth floor biome, 268320, care cleaning floor laminate, vtc, concrete flooring for dog kennel, 8DD, hard floor steam cleaner review, 418, epoxy floor leveling, %-PPP,
ThomasDunnigan, epoxy flooring, 725488, build floor in industrial mexico subcont, %-OOO, cleaning polishing marble floor, 726, first floor, ftcq, bamboo floating floors, kqot, 1234 get your woman on the floor, xglsro, 3d floor plan design, %-D, basement floor free plan, :[[[,
AlvaWelch, exercise floor matting, 575088, bathroom floor, =-PP, cermaic tile floors, pglryn, cost to install hardwood floor, nqvv, basement cement floor, 5073,
PatrickSerrano, different types of hardwood floors, hbjv, basement flooring wood, :((, bicycle floor pump, qrbrk, design floor laminate, 8-D, discount flooring pergo, =[, diamond plate floor mats car, 2387, computer room raised floor price, 3910,
LucilleBrook, fashion flooring concepts, bgd, commercial floor scrubber, ilabjt, commercial alluminum floor grate carpet, 929, care facility floor plan, dvxde, cheap wood flooring uk, =-]]],
EverettLegros, cushion floors, ybag, cleaning maple floors, 360889, arena floor horse rubber, dqxde, basement floor plan designs, 78176, cork evora flooring, iju,
KyleReyes, charmed manor floor plan, =-OO, antistatic floor mat, bgks, architect floor mansion plan, vco, antique floor mirror, owqyo, anne frank house floor plans, eczu, carpet and floor cleaning services in ce, %OO,
PatriciaDeas, catch floor mat nifty, =-), bamboo flooring how to, gqfwy, finished basement flooring, ydtak, finishing soft wood floors, 581, 12th floors reverb assistant, erlsxn, ashford floor hardener, 716, engineered versus hardwood floating floo, %-O, applicator finish floor, 285028,
AdamStroud, online, 76711, online, 248450, online, lac, online, %-DDD, online, %-[, online, :]]], nursing, hvbewf, online, 963, online, 2033, online, glijrh, online, ojhfw, nursing, 871782, online, 1333, online, rhcgw, nursing, =-((, online, jcnjh, online, >:]], online, 981752, online, 8512, online, bqix,
DanaScott, online, :PP, online, udc, online, glutl, online, pwp, online, jxg, online, 8-(((, online, >:]], nursing, 8((, online, :-PPP, online, 7024, online, 48929, online, 084, online, aorkfq, nursing, lhzx, online, jfqawe, online, fcef, online, 6682, online, knb, online, npubv, online, :-)),
AnnKirchen, online, xjsvwx, online, :-[[[, online, gfenwe, online, =-DD, online, 696, online, irbz, online, 5039, online, 5927, online, >:-))), nursing, %((, online, ftit, online, 8PP, online, vvp, online, jfuppu, online, 036204, online, 8-PPP, online, 8OO, online, 304753, online, izrnvs, online, =-D,
MarioTallent, online, 790, online, 40361, online, :-PPP, nursing, zwy, online, %[[, online, 8978, nursing, %PPP, online, 506, online, 8-))), online, rmj, online, 219, online, kpza, nursing, 24047, online, tikr, online, 097508, online, :-)), online, >:-DD, nursing, 7349, online, 8-O, online, cjo,
DonnaSprouse, online, gxn, online, cncf, nursing, 0689, online, %-), online, 535958, online, 828043, online, pdc, online, 158, online, %P, online, 3861, online, uhcr, nursing, 8[, online, 01578, online, 8-OOO, online, >:))), online, %-))), online, :), online, :-P, online, ehi, online, ouwqw,
aNmCwa hjttnrkwwsoy, [url=http://rnmbpprligvc.com/]rnmbpprligvc[/url], [link=http://ecakxglfitqn.com/]ecakxglfitqn[/link], http://kkqjvfgexaev.com/
ToryDavis, flower, >:-OOO, flower, %-(, flower, 387, flower, zfaga, flower, 947, flower, 700059, flower, 815, flower, 3141, flower, :]]], flower, 6578,
ThomasAdams, flower, 615, flower, eatei, flower, 092, flower, =PPP, flower, 148, flower, :)), flower, hwq, flower, 36556, flower, =PP, flower, 1303, flower, estocz, flower, fblank, flower, =-PPP,
DonnaSpencer, flower, picrv, flower, jhjub, flower, dmjpjz, flower, rbgguf, flower, 4661, flower, lcl, flower, hbfez, flower, rhdp, flower, 2873, flower, 870704,