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 it.javascript.info — Chiamata di funzione

  • Tutorial
  • Il linguaggio JavaScript
  • Tipi di dato
  • Array
torna alle lezioni

Chiamata di funzione

importanza: 5

Qual è il risultato? Perché?

let arr = ["a", "b"];

arr.push(function() {
  alert( this );
})

arr[2](); // ?

La chiamata arr[2]() è sintatticamente equivalente a obj[method](); al posto di obj abbiamo arr, e al posto di method abbiamo 2.

Quindi abbiamo una chiamata al metodo arr[2]. Naturalmente, riceve il riferimento a this e ritorna l’array:

let arr = ["a", "b"];

arr.push(function() {
  alert( this );
})

arr[2](); // a,b,function(){...}

L’array ha 3 valori: inizialmente ne ha due, successivamente viene aggiunta la funzione.

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.