Expand description
Traits for working with JavaScript objects.
This module defines the Object
trait, which is implemented
by all object types in the JavaScript type hierarchy. This
trait provides key operations in the semantics of JavaScript objects,
such as getting and setting an object’s properties.
§Property Keys
Object properties are accessed by a property key, which in JavaScript
can be a string or symbol. (Neon does not yet have support for
symbols.) For convenience, the PropertyKey
trait allows
Neon programs to use various Rust string types, as well as numeric types,
as keys when accessing object properties, converting the keys to strings
as necessary:
fn set_and_check<'a>(
cx: &mut impl Context<'a>,
obj: Handle<'a, JsObject>
) -> JsResult<'a, JsValue> {
let value = cx.string("hello!");
// set property "17" with integer shorthand
obj.set(cx, 17, value)?;
// get property "17" with string shorthand
// returns the same value ("hello!")
obj.get(cx, "17")
}
Traits§
- The trait of all object types.
- A property key in a JavaScript object.