Struct rquickjs_core::Class [−][src]
pub struct Class<'js, C>(_, _);
classes
only.Expand description
The class object interface
Implementations
Wrap constructor of class
Instantiate the object of class
Instantiate the object of class with given prototype
Get reference from object
Get mutable reference from object
Register the class using raw context
Safety
This function must only be called from js_module_init
function or should be called right after context initialization.
From Rust code you should use Class::register instead.
Get class from value
Convert to object
Convert to value
Methods from Deref<Target = Object<'js>>
Initialize an object using ObjectDef
check wether the object contains a certain key.
Set a member of an object to a certain value
Get own string enumerable property names of an object
Get own property names of an object
Get own string enumerable properties of an object
Get own properties of an object
Get own string enumerable property values of an object
Get own property values of an object
Get an object prototype
Set an object prototype
Check the object for instance of
pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()> where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
This is supported on crate feature properties
only.
pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()> where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
properties
only.Define a property of an object
// Define readonly property without value
obj.prop("no_val", ()).unwrap();
// Define readonly property with value
obj.prop("ro_str", "Some const text").unwrap();
// Define readonly property with value and make it to be writable
obj.prop("ro_str2", Property::from("Some const text").writable()).unwrap();
// Define readonly property using getter and make it to be enumerable
obj.prop("ro_str_get", Accessor::from(|| "Some readable text").enumerable()).unwrap();
// Define readonly property using getter and setter
obj.prop("ro_str_get_set",
Accessor::from(|| "Some text")
.set(|new_val: String| { /* do something */ })
).unwrap();