mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-02 02:11:06 +00:00
bindings for Function.prototype.bind()
This commit is contained in:
parent
cf08aee341
commit
f850a6fafc
@ -325,6 +325,13 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Function;
|
pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Function;
|
||||||
|
|
||||||
|
/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
|
||||||
|
/// with a given sequence of arguments preceding any provided when the new function is called.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn bind(this: &Function, context: &JsValue) -> Function;
|
||||||
|
|
||||||
/// The length property indicates the number of arguments expected by the function.
|
/// The length property indicates the number of arguments expected by the function.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
|
||||||
|
@ -38,6 +38,46 @@ fn apply() {
|
|||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bind() {
|
||||||
|
project()
|
||||||
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn bind(this: &js::Function, context: &JsValue) -> js::Function {
|
||||||
|
this.bind(context)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
const obj = {
|
||||||
|
a: 0,
|
||||||
|
fn: function () {
|
||||||
|
return this.a + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const boundFn = wasm.bind(obj.fn, { a: 41 });
|
||||||
|
assert.equal(boundFn(), 42);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length() {
|
fn length() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user