¿Por qué no puedo omitir el parámetro getElementById () en la función de flecha?
Di que tengo 3<img>
etiquetas en una página, y me gustaría obtenerlas como una matriz, así que escribí:
let myArray = ['img1', 'img2', 'img3'].map(id => document.getElementById(id));
... que funcionó bien.
Entonces pensé, oye,getElementById
toma exactamente 1 argumento. ¿No hay un azúcar de sintaxis para eso? Entonces escribí:
let myArray = ['img1', 'img2', 'img3'].map(document.getElementById);
... pero eso no funcionó. Obtuve "Invocación ilegal" en Chrome.
Entonces no es sintaxis de azúcar entonces. ¿Qué hay detrás de todo esto?