Google
 
Web itpro-blogger.blogspot.com
土曜日, 6月 27, 2009

[JavaScript]パラメータの無いメソッド

▼質問
canvasの幅と高さを次の様に取得しようとしたんだがうまくいかないんだ。

exGraph.getCanvas = function( id ) {
/* canvas要素のノードオブジェクト */
var el = document.getElementById( id );
this.canvas = el;
/* 2Dコンテキスト */
this.context_ = this.canvas.getContext( '2d' );
/* canvas要素の幅・高さ */
this.getWidth = function() { return this.canvas.width; };
this.getHeight = function() { return this.canvas.height; };
};

var obj = new exGraph.getCanvas( "sample" );
/* canvasエリアの幅・高さを取得する */
var width = obj.getWidth;

どうしてか教えてくれ!

▼回答
取得する時のコードが間違っているよ。

括弧が足りないんだ!

var width = obj.getWidth();

メソッドの括弧は省略できないんだ。

VBみたいに・・・。






Comments: コメントを投稿

<< Home

This page is powered by Blogger. Isn't yours?