pub struct Class<V: JSValueImpl>(/* private fields */);Expand description
Represents a JavaScript class constructor
This struct encapsulates a JavaScript object that serves as a class constructor. It is used to create class instances and manage class lifecycle.
Implementations§
Source§impl<V> Class<V>where
V: JSValueImpl + JSObjectOps,
impl<V> Class<V>where
V: JSValueImpl + JSObjectOps,
Sourcepub fn instance<JC: JSClass<V>>(self, value: JC) -> JSObject<V>
pub fn instance<JC: JSClass<V>>(self, value: JC) -> JSObject<V>
Create a new instance of the class
Sourcepub fn instance_of<JC: JSClass<V>>(object: &JSObject<V>) -> bool
pub fn instance_of<JC: JSClass<V>>(object: &JSObject<V>) -> bool
Check if the object is an instance of the specified class
Sourcepub fn lookup<JC: JSClass<V>>(context: &JSContext<V::Context>) -> JSResult<Self>
pub fn lookup<JC: JSClass<V>>(context: &JSContext<V::Context>) -> JSResult<Self>
Returns the registered constructor for a class type.
pub fn prototype<JC: JSClass<V>>( context: &JSContext<V::Context>, ) -> JSResult<JSObject<V>>
Sourcepub fn from_object<JC: JSClass<V>>(obj: &JSObject<V>) -> Option<Self>
pub fn from_object<JC: JSClass<V>>(obj: &JSObject<V>) -> Option<Self>
Methods from Deref<Target = JSObject<V>>§
Sourcepub fn borrow<T>(&self) -> JSResult<Ref<'_, T>>where
T: JSClass<V>,
pub fn borrow<T>(&self) -> JSResult<Ref<'_, T>>where
T: JSClass<V>,
Borrow the underlying data from an instance
Sourcepub fn borrow_mut<T>(&self) -> JSResult<RefMut<'_, T>>where
T: JSClass<V>,
pub fn borrow_mut<T>(&self) -> JSResult<RefMut<'_, T>>where
T: JSClass<V>,
Mutably borrow the underlying data from an instance
pub fn prototype(&self, proto: JSObject<V>) -> bool
Sourcepub fn to_json_string(&self) -> JSResult<String>
pub fn to_json_string(&self) -> JSResult<String>
Convert JSObject to JSON string using JavaScript’s JSON.stringify
pub fn set<'a, K, KV>(&'a self, k: K, kv: KV) -> JSResult<&'a Self>
pub fn define_property<'a, K>(
&'a self,
k: K,
descriptor: PropertyDescriptor<V>,
) -> JSResult<&'a Self>where
K: Into<PropertyKey<'a, V>>,
pub fn delete<'a, K>(&'a self, k: K) -> JSResult<bool>where
K: Into<PropertyKey<'a, V>>,
pub fn has_property<'a, K>(&self, k: K) -> JSResult<bool>where
K: Into<PropertyKey<'a, V>>,
pub fn get<'a, K, T>(&'a self, k: K) -> JSResult<T>
pub fn get_opt<'a, K, T>(&'a self, k: K) -> JSResult<Option<T>>
pub fn as_js_value(&self) -> &JSValue<V>
Sourcepub fn entries(&self) -> JSResult<Vec<Entry<V>>>
pub fn entries(&self) -> JSResult<Vec<Entry<V>>>
Returns an iterator over the object’s own enumerable string-keyed property [key, value] pairs.
Sourcepub fn entries_as<K, V2>(&self) -> JSResult<Vec<(K, V2)>>where
K: FromJSValue<V>,
V2: FromJSValue<V>,
pub fn entries_as<K, V2>(&self) -> JSResult<Vec<(K, V2)>>where
K: FromJSValue<V>,
V2: FromJSValue<V>,
Returns entries with converted types
Sourcepub fn own_keys(&self) -> JSResult<Vec<V>>
pub fn own_keys(&self) -> JSResult<Vec<V>>
Returns an array of a given object’s own enumerable property names
Sourcepub fn values(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>
pub fn values(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>
Returns an iterator over the object’s own enumerable string-keyed property values.
Sourcepub fn values_as<T>(&self) -> JSResult<Vec<T>>where
T: FromJSValue<V>,
pub fn values_as<T>(&self) -> JSResult<Vec<T>>where
T: FromJSValue<V>,
Returns values with converted type
Sourcepub fn keys(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>
pub fn keys(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>
Returns an iterator over the object’s own enumerable string-keyed property names.
Sourcepub fn keys_as<K>(&self) -> JSResult<Vec<K>>where
K: FromJSValue<V>,
pub fn keys_as<K>(&self) -> JSResult<Vec<K>>where
K: FromJSValue<V>,
Returns keys with converted type