This AI is still in early stages of development.
object.addProp()
- Aubergine
Owned by Aubergine
Adds a new accessor (getter/setter) or data (value) property to any object, setting it's enumerable, configurable and read-only flags as desired...
Syntax
obj.addProp(mask, key, val_get[, set]);
Where obj is any object in the Javascript environment.
Parameters
Parameter | Type | Mandatory | Description | Util.js version |
---|---|---|---|---|
mask | Number constant | A constant describing the property descriptor settings:
| 1.0 | |
key | String | The name (key) of the property as a string. | 1.0 | |
val_get | Variant or Function | If you're defining a data property, this parameter can be any Javascript value, function or object. If you're defining an accessor property (getter/setter) then this parameter is the getter function. | 1.0 | |
set | Function | If you're defining an accessor property (getter/setter) then this parameter is the setter function. If your accessor is read-only, you don't need to specify a setter function. | 1.0 |
Return value
Value | Type | Notes | API Version |
---|---|---|---|
<object> | Object | If successful, the addProp() method returns the modified object. | 1.0 |
<error> | TypeError | An error will be thrown if:
| 1.0 |
Example
Add .isAlly, .isEnemy and .isMe properties to Player Obejcts
// See https://warzone.atlassian.net/wiki/display/EGG/Function+Manipulation // For info on curry() and wraps() var isAlly = allianceExistsBetween.curry(me); var NOT = funciton(bool) { return !bool; } var isEnemy = NOT.wraps(isAlly); // Iterate the playerData array and add properties to objects playerData.forEach(function(player, id) { // using .addAccessor() would be more concise playerData[id].addProp( ACCESSOR_HIDDEN, "isAlly", isAlly.curry(id) ); playerData[id].addProp( ACCESSOR_HIDDEN, "isEnemy", isEnemy.curry(id) ); // using .addConst() would be more concise playerData[id].addProp( DATA_HIDDEN_READONLY, "isMe", (id == me) ); }); playerData[somePlayer].isAlly; // true or false // etc...
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...
See also
Related articles:
- defineProperty – Mozilla Developer Network page that inspired this .addProp() function