Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page >

getterとsetter

最新のWeb Kitビルド(webkit.orgから入手可能)には、getter関数とsetter関数のサポートが含まれています。これらの関数は変数のように動作しますが、実際には関数を呼び出して、プロパティを構成している基盤の値を変更します。getterの宣言は、次のような形式をとります。

myObject.__defineGetter__( "myGetter", function() { return this.myVariable; } );

getter関数は、これが使われるときには、代入演算の中で戻り値が使われるため、次のように値を返すことが不可欠です。

var someVariable = myObject.myGetter;

getterと同様に、setterはオブジェクトで定義され、キーワードと関数を提供します。

myObject.__defineSetter__( "mySetter", function(aValue) { this.myVariable = aValue; } );

setter関数は、次のように、代入文で使われる引数を受け取る必要があります。

myObject.mySetter = someVariable;


< Previous PageNext Page >


Last updated: 2007-06-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice