← 返回首页
Second bind
EN

We want to make this open-source project available for people all around the world.

Help to translate the content of this tutorial to your language!

    Search
    Search
    Light themeDark theme
    عربيDanskEnglishEspañolفارسیFrançaisIndonesiaItaliano日本語한국어РусскийTürkçeУкраїнськаOʻzbek简体中文
    back to the lesson

    Second bind

    importance: 5

    Can we change this by additional binding?

    What will be the output?

    function f() { alert(this.name); } f = f.bind( {name: "John"} ).bind( {name: "Ann" } ); f();
    solution

    The answer: John.

    function f() { alert(this.name); } f = f.bind( {name: "John"} ).bind( {name: "Pete"} ); f(); // John

    The exotic bound function object returned by f.bind(...) remembers the context (and arguments if provided) only at creation time.

    A function cannot be re-bound.