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 uk.javascript.info — Друга прив’язка

  • Підручник
  • Мова програмування JavaScript
  • Розширена робота з функціями
  • Прив’язка контексту до функції
назад до уроку

Друга прив’язка

важливість: 5

Чи можемо ми змінити this за допомогою додаткового прив’язування?

Який результат буде виведено?

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

f = f.bind( {name: "Іван"} ).bind( {name: "Христя" } );

f();

Відповідь: Іван.

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

f = f.bind( {name: "Іван"} ).bind( {name: "Христя"} );

f(); // Іван

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.