最近の記事
- 9/1 - 将棋始めました
- 5/16 - サーバー引っ越し
- 4/24 - 優先順位
- 3/17 - vbNullString と 空文字列 ""
- 3/15 - InputBox 関数の戻り値
- 3/13 - 紙と Excel と VBA
- 3/9 - 未だに Visual Basic 6
- 11/14 - ぼて閉鎖
- 11/9 - 関数オブジェクトの呼び出し
- 9/7 - メソッドとしての関数オブジェクト
Entering Passive Mode
function getThisValue() {
return this.value;
}
function setThisValue(value) {
this.value = value;
}
function Foo() {
this.value = 0;
this.getValue = getThisValue;
this.setValue = setThisValue;
}
var foo = new Foo();
foo.setValue(3 * 5);
alert(foo.getValue()); // 15
JavaScript では、メソッドもまた関数オブジェクトである。
JavaScript においては、メソッドはプロパティの一種であり、
オブジェクトのプロパティに関数オブジェクトを代入すると、
それはメソッドとして呼び出せるようになる。