__defineSetter__ and __defineGetter__
You can use scripting to add properties to the prototypes of some of these static objects. To do so, you must use new features added to NN6. Two new methods— __defineGetter__() and __defineSetter__()—enable you to assign functions to a custom property of an object.
The functions execute whenever the property is read (the function assigned via
the __defineGetter__() method) or modified (the function assigned via the
__defineSetter__() method). The common way to define these functions is in
the form of an anonymous function. The formats for the two statements
that assign these behaviors to an object prototype are as follows:
object.prototype.__defineGetter__("propName", function([param1[,...[,paramN]]])
{
// statements
return returnValue
})
object.prototype.__defineSetter__("propName", function([param1[,...[,paramN]]])
{
// statements
return returnValue
})
The functions execute whenever the property is read (the function assigned via
the __defineGetter__() method) or modified (the function assigned via the
__defineSetter__() method). The common way to define these functions is in
the form of an anonymous function. The formats for the two statements
that assign these behaviors to an object prototype are as follows:
object.prototype.__defineGetter__("propName", function([param1[,...[,paramN]]])
{
// statements
return returnValue
})
object.prototype.__defineSetter__("propName", function([param1[,...[,paramN]]])
{
// statements
return returnValue
})
Comments
Post a Comment
Feel free to give constructive feedback or let me know if it was helpful.