Declared in: itkJavaScript/ITKJSProperties.h
ITKJSProperties is an informal protocol to define the semantics of getting, setting, deleting, and enumerating JavaScript properties of Objective-C objects.
All JavaScript objects have properties. These are accessible via the object.property
and object[property]
syntax. If the JavaScript object happens to be a Joy reflection of an Objective-C object, the object can implement this protocol to determine what its JavaScript properties refer to.
The default behaviour for Objective-C objects (without implementing ITKJSProperties) is as follows:
#ivars
is hard-coded to be the C struct containing all the object's instance variables. The ITKJSProperties methods will never get called for this slot, so you can't redefine its behaviour.
0
by default means the same as #ivars
, so you can say *object
and object->ivar
. You can redefine this, though.
object.property
instead of accessor methods. The itkJavaScript framework already provides implementations of ITKJSProperties for the NSArray and NSDictionary classes.
getJSProperty:
(JSVal)slot value:
(JSVal *)vpOn entry, vp will contain the current value of the property as remembered by JavaScript. You can change it, or leave it alone. Return YES if your method has already placed the authoritative value of slot into vp, or NO if you want to leave the default behaviour detailed above.
setJSProperty:
(JSVal)slot value:
(JSVal *)vpOn entry, vp will contain the assigned value. You can modify it in place if it needs to be coerced somehow. Return YES if your method has already taken all necessary actions for assigning to slot, or NO if you still want the default behaviour to happen.
delJSProperty:
(JSVal)slot value:
(JSVal *)vpOn entry, vp will contain 'true'. You can modify it to 'false' if slot can't possibly be removed from the object. (To report an error, raise an exception.) Return YES if your method already took all necessary actions for removing slot, or NO if you still want the default behaviour to happen.
jsPropertyEnumerator
If implemented, defines the behaviour of loops like for (i in object)
. The variable i
will take on all values returned by the property enumerator's getNextJSProperty:
method.