マキノ式@Blogger

マキノ式@ブログ! Java関連をベースとしてWEBとかプログラミングとか

5.02.2005

Ajax関連:JavaScriptでConstructor

JavaScriptって意外に面白いな~。
コンストラクタを書いて、外部の関数オブジェクトを渡せるんだ~。
熱いね!!

これはほんの一例:

function PageManager(tableDrawerFunction){

//フィールドに格納
this.page = 0;
this.countPerPage = 10;

//drawフィールドに引数の関数オブジェクトを格納
this.draw = tableDrawerFunction;

//無名関数オブジェクトをフィールドに格納
this.startCount = function(){
return this.page * this.countPerPage;
}

this.endCount = function(){
return (this.page + 1) * this.countPerPage;
}

this.nextPage = function(){
this.page++;
this.draw();
}

this.prevPage = function(){
this.page--;
if( this.page < 0 )this.page = 0;
this.draw();
}
}


参考サイト:JavaScript 講座