Hidden Features of JavaScript

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

  What "Hidden Features" of JavaScript do you think every programmer should know?   

After having seen the excellent quality of the answers to the following questions I thought it was time to ask it for JavaScript.

Even though JavaScript is arguably the most important Client Side language right now (just ask Google) it s surprising how little most web developers appreciate how powerful it really is.

Answers

You don t need to define any parameters for a function. You can just use the function s arguments array-like object.

function sum() {
    var retval = 0;
    for (var i = 0, len = arguments.length; i < len; ++i) {
        retval += arguments[i];
    }
    return retval;
}

sum(1, 2, 3) // returns 6

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/61088/hidden-features-of-javascript

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils