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 ja.javascript.info — 2つの bind

  • チュートリアル
  • JavaScript 言語
  • 関数の高度な機能
  • 関数バインディング
レッスンに戻る

2つの 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(...) によって返却された バインドされた関数 オブジェクトは作成時にのみコンテキスト(と提供されていれば引数を)を覚えます。

関数を再バインドすることはできません。

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.