Allow function argument overloading on custom JavaScript classes

This commit is contained in:
Tobie Morgan Hitchcock 2023-02-12 15:51:47 +00:00
parent 612cd39b05
commit 6556de7cd2
3 changed files with 6 additions and 6 deletions

View file

@ -17,7 +17,7 @@ pub mod duration {
impl Duration { impl Duration {
#[quickjs(constructor)] #[quickjs(constructor)]
pub fn new(value: String) -> Self { pub fn new(value: String, args: Rest<Value>) -> Self {
Self { Self {
value, value,
} }
@ -27,7 +27,7 @@ pub mod duration {
&self.value &self.value
} }
/// Convert the object to a string /// Convert the object to a string
pub fn toString(&self) -> String { pub fn toString(&self, args: Rest<Value>) -> String {
self.value.to_owned() self.value.to_owned()
} }
/// Convert the object to JSON /// Convert the object to JSON

View file

@ -19,7 +19,7 @@ pub mod record {
impl Record { impl Record {
#[quickjs(constructor)] #[quickjs(constructor)]
pub fn new(tb: String, id: String) -> Self { pub fn new(tb: String, id: String, args: Rest<Value>) -> Self {
Self { Self {
tb, tb,
id, id,
@ -34,7 +34,7 @@ pub mod record {
&self.id &self.id
} }
/// Convert the object to a string /// Convert the object to a string
pub fn toString(&self) -> String { pub fn toString(&self, args: Rest<Value>) -> String {
format!("{}:{}", self.tb, self.id) format!("{}:{}", self.tb, self.id)
} }
/// Convert the object to JSON /// Convert the object to JSON

View file

@ -17,7 +17,7 @@ pub mod uuid {
impl Uuid { impl Uuid {
#[quickjs(constructor)] #[quickjs(constructor)]
pub fn new(value: String) -> Self { pub fn new(value: String, args: Rest<Value>) -> Self {
Self { Self {
value, value,
} }
@ -27,7 +27,7 @@ pub mod uuid {
&self.value &self.value
} }
/// Convert the object to a string /// Convert the object to a string
pub fn toString(&self) -> String { pub fn toString(&self, args: Rest<Value>) -> String {
self.value.to_owned() self.value.to_owned()
} }
/// Convert the object to JSON /// Convert the object to JSON