Struct rquickjs_core::function::Function
source · pub struct Function<'js>(_);
Expand description
Rust representation of a javascript function.
Implementations§
source§impl<'js> Function<'js>
impl<'js> Function<'js>
pub fn new<F, A, R>(ctx: Ctx<'js>, func: F) -> Result<Self>where F: AsFunction<'js, A, R> + 'js,
sourcepub fn set_length(&self, len: usize) -> Result<()>
pub fn set_length(&self, len: usize) -> Result<()>
Set the length
property
sourcepub fn call<A, R>(&self, args: A) -> Result<R>where
A: AsArguments<'js>,
R: FromJs<'js>,
pub fn call<A, R>(&self, args: A) -> Result<R>where A: AsArguments<'js>, R: FromJs<'js>,
Call a function with given arguments
You can use tuples to pass arguments. The ()
treated as no arguments, the (arg,)
as a single argument and so on.
To call function on a given this
you can pass This(this)
as a first argument.
By default an undefined
will be passed as this
.
sourcepub fn construct<A, R>(&self, args: A) -> Result<R>where
A: AsArguments<'js>,
R: FromJs<'js>,
pub fn construct<A, R>(&self, args: A) -> Result<R>where A: AsArguments<'js>, R: FromJs<'js>,
Call a constructor with given arguments
You can use tuples to pass arguments. The ()
treated as no arguments, the (arg,)
as a single argument and so on.
To call constructor on a given this
you can pass This(this)
as a first argument.
sourcepub fn defer_call<A>(&self, args: A) -> Result<()>where
A: AsArguments<'js>,
pub fn defer_call<A>(&self, args: A) -> Result<()>where A: AsArguments<'js>,
Deferred call a function with given arguments
You can use tuples to pass arguments. The ()
treated as no arguments, the (arg,)
as a single argument and so on.
To call function on a given this
you can pass This(this)
as a first argument.
By default an undefined
will be passed as this
.
sourcepub fn is_constructor(&self) -> bool
pub fn is_constructor(&self) -> bool
Check that function is a constructor
sourcepub fn set_constructor(&self, flag: bool)
pub fn set_constructor(&self, flag: bool)
Mark the function as a constructor
sourcepub fn set_prototype(&self, proto: &Object<'js>)
pub fn set_prototype(&self, proto: &Object<'js>)
Set a function prototype
Actually this method does the following:
func.prototype = proto;
proto.constructor = func;
sourcepub fn get_prototype(&self) -> Result<Object<'js>>
pub fn get_prototype(&self) -> Result<Object<'js>>
Get a function prototype
Actually this method returns the func.prototype
.
sourcepub fn into_object(self) -> Object<'js>
pub fn into_object(self) -> Object<'js>
Convert into an object
sourcepub fn from_object(object: Object<'js>) -> Result<Self>
pub fn from_object(object: Object<'js>) -> Result<Self>
Convert from an object
Methods from Deref<Target = Value<'js>>§
pub fn is_null(&self) -> bool
pub fn is_undefined(&self) -> bool
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if the value is a function
sourcepub unsafe fn ref_string(&self) -> &String<'js>
pub unsafe fn ref_string(&self) -> &String<'js>
sourcepub unsafe fn ref_symbol(&self) -> &Symbol<'js>
pub unsafe fn ref_symbol(&self) -> &Symbol<'js>
sourcepub unsafe fn ref_object(&self) -> &Object<'js>
pub unsafe fn ref_object(&self) -> &Object<'js>
sourcepub unsafe fn ref_function(&self) -> &Function<'js>
pub unsafe fn ref_function(&self) -> &Function<'js>
sourcepub fn as_function(&self) -> Option<&Function<'js>>
pub fn as_function(&self) -> Option<&Function<'js>>
Try reinterprete as
sourcepub unsafe fn ref_big_int(&self) -> &BigInt<'js>
pub unsafe fn ref_big_int(&self) -> &BigInt<'js>
sourcepub fn as_big_int(&self) -> Option<&BigInt<'js>>
pub fn as_big_int(&self) -> Option<&BigInt<'js>>
Try reinterprete as