defineProperty(_:descriptor:)
Defines a property on the JavaScript object value or modifies a property’s definition.
Declaration
func defineProperty(_ property: Any!, descriptor: Any!)func defineProperty(_ property: String!, descriptor: Any!)Parameters
- property:
The name of the property to define or modify.
- descriptor:
A JavaScript object whose keys and values define the property’s behavior.
Discussion
Calling this method is equivalent to using the Object.defineProperty method in JavaScript. The descriptor parameter has the same format required by that JavaScript method; for convenience when calling from Objective-C or Swift, you can also construct it as a dictionary with the keys listed in Property Descriptor Keys.
The descriptor determines the behavior of the JavaScript property, and must fit one of three cases:
Data Descriptor: Contains one or both of the keys
valueandwritable, and optionally also contains the keysenumerableorconfigurable. Cannot contain the keysgetorset. Use a data descriptor to create or modify the attributes of a data property on an object (replacing any existing accessor property).Accessor Descriptor: Contains one or both of the keys
getorset, and optionally also contains the keysenumerableorconfigurable. Cannot contain the keysvalueandwritable. Use an accessor descriptor to create or modify the attributes of an accessor property on an object (replacing any existing data property).Generic Descriptor: Contains one or both of the keys
enumerableorconfigurable, and cannot contain any other keys. Use a genetic descriptor to modify the attributes of an existing data or accessor property, or to create a new data property.