javascript by example
javascript by example
javascript by example
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Capitolo 1<br />
if (iterable.toArray) {<br />
return iterable.toArray();<br />
}<br />
else {<br />
//altrimenti aggiunge i membri della collection a un nuovo Array<br />
//e ritorna quest'ultimo<br />
}<br />
}<br />
var results = [];<br />
for (var i = 0; i < iterable.length; i++)<br />
results.push(iterable[i]);<br />
return results;<br />
Linguaggio<br />
In questo modo, applicando la trasformazione, la funzione vista<br />
in precedenza funzionerà correttamente con:<br />
function fx (){<br />
alert($A(arguments).pop())<br />
}<br />
fx(1,2,3,4);<br />
30 Aggiungere il metodo foreach agli Array<br />
Uno dei costrutti più usati in Javascript è il classico ciclo for per<br />
scorrere gli Array:<br />
var a = [1,2,3,4,5];<br />
for(var i=0;i