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 fr.javascript.info — Bound function as a method

  • Tutoriel
  • JavaScript le langage
  • Travail avancé avec les fonctions
  • Le "bind" de fonction
retour au cours
Ce contenu n'est disponible que dans les langues suivantes :Čeština, Dansk, English, Español, فارسی, Indonesia, Italiano, 日本語, 한국어, Русский, Türkçe, Українська, Oʻzbek, 简体中文. Merci de

Bound function as a method

importance: 5

What will be the output?

function f() {
  alert( this ); // ?
}

let user = {
  g: f.bind(null)
};

user.g();

The answer: null.

function f() {
  alert( this ); // null
}

let user = {
  g: f.bind(null)
};

user.g();

The context of a bound function is hard-fixed. There’s just no way to further change it.

So even while we run user.g(), the original function is called with this=null.

You are visitor 01402520 — 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.