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 es.javascript.info — LLamados en un contexto de array

  • Tutorial
  • El lenguaje JavaScript
  • Tipos de datos
  • Arrays
regresar a la lección

LLamados en un contexto de array

importancia: 5

¿Cuál es el resultado y por qué?

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

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

arr[2](); // ?

El llamado a arr[2]() es sintácticamente el buen y viejo obj[method](), en el rol de obj tenemos arr, y en el rol de method tenemos 2.

Entonces tenemos una llamada a función arr[2] como un método de objeto. Naturalmente, recibe this referenciando el objeto arr y su salida es el array:

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

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

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

El array tiene 3 valores: Inicialmente tenía 2 y se agregó la función.

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.