proto_method

Macro proto_method 

Source
macro_rules! proto_method {
    ($class:expr, $method:expr, $body:expr) => { ... };
}
Expand description

Create a method assignment on a prototype with Vec body. This is a more ergonomic wrapper around fn_assign! for the common case.

§Examples

let body_stmts = vec![
    ts_quote!( const result = {}; as Stmt ),
    ts_quote!( return result; as Stmt ),
];

// Simple: Class.prototype.method = function() { body }
let stmt = proto_method!(MyClass, "toJSON", body_stmts);

// With dynamic class name:
let class_ident = ident!("User");
let stmt = proto_method!(class_ident, "toString", body_stmts);