This AI is still in early stages of development.
object.addAccessor()
- Aubergine
Owned by Aubergine
Add a hidden, non-configurable accessor property to any object...
Syntax
obj.addAccessor(key, getter[, setter]);
Parameters
Parameter | Type | Mandatory | Description | Util.js version |
---|---|---|---|---|
key | String | The name (key) of the property. | 1.0 | |
getter | Function | The getter function to associate with the property. | 1.0 | |
setter | Function | The setter function to associate with the property. | 1.0 |
Return value
Value | Type | Notes | API Version |
---|---|---|---|
<object> | Object | If successful, the addAccessor() method returns the modified object. | 1.0 |
<error> | TypeError | An error will be thrown if:
| 1.0 |
Example
Adding a property to an object...
myObj = {}; var _foo = []; myObj.addAccessor( "foo", function getter() { return _foo; }, function setter(val) { _foo.push(val); } ); myObj.foo; // [] myObj.foo = true; myObj.foo; // [true] myObj.foo = false; myObj.foo; // [true, false] myObj.foo.push(null); myObj.foo; // [true, false, null] for (var i in myObj) { // does not iterate foo (foo is hidden) } for (var i in myObj.foo) { // 0, 1, 2 }
Contents
Jump to:
Property Definitions
Topics:
- object.addAccessor() — Add a hidden, non-configurable accessor property to any object...
- object.addProp() — Adds a new accessor (getter/setter) or data (value) property to any object, setting it's enumerable, configurable and read-only flags as desired...
- ACCESSOR_HIDDEN_CONFIG — A non-enumerable, configurable accessor property.
- DATA_HIDDEN_CONFIG — A non-enumerable, configurable, writable data property.
- ACCESSOR_NORMAL — An enumerable, non-configurable accessor property.
- DATA_READONLY — An enumerable, non-configurable, read-only data property.
- DATA_READONLY_HIDDEN — A non-enumerable, non-configurable, read-only data property.
- ACCESSOR_HIDDEN — A non-enumerable, non-configurable accessor property.
- DATA_READONLY_CONFIG — An enumerable, configurable, read-only data property.
- ACCESSOR_NORMAL_CONFIG — An enumerable, configurable accessor property.
- DATA_NORMAL — An enumerable, non-configurable, writable data property.
- DATA_READONLY_HIDDEN_CONFIG — A non-enumerable, configurable, read-only data property.
- DATA_HIDDEN — A non-enumerable, non-configurable, writable data property.
- object.addConst() — Add a hidden, read-only data property to any object...