GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing zh.javascript.info — 二次 bind

  • 教程
  • JavaScript 编程语言
  • 函数进阶内容
  • 函数绑定
回到课程

二次 bind

重要程度: 5

我们可以通过额外的绑定改变 this 吗?

输出将会是什么?

function f() {
  alert(this.name);
}

f = f.bind( {name: "John"} ).bind( {name: "Ann" } );

f();

答案:John。

function f() {
  alert(this.name);
}

f = f.bind( {name: "John"} ).bind( {name: "Pete"} );

f(); // John

f.bind(...) 返回的外来(exotic)绑定函数 对象仅在创建的时候记忆上下文(以及参数,如果提供了的话)。

一个函数不能被重绑定(re-bound)。

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.