Walid-Shouman
10/10/2016 - 12:50 PM

javascript functions notes

javascript functions notes

Anonymous functions

Javascript advanced tutorial for beginners and experienced developers gives good examples for them.
Anonymous functions could be useful for:

  • function expressions
  • inside an object
  • event handlers
  • self invoking functions

To call anonymous functions use arguments.callee()

Class functions

A well-documented code snippet for how function could be attached to some class.
Reference: JSDoc constructor example.

/** @constructor */
Person = function() {
    this.say = function() {
        return "I'm an instance.";
    }

    function say() {
        return "I'm inner.";
    }
}
Person.say = function() {
    return "I'm static.";
}

var p = new Person();
p.say();      // I'm an instance.
Person.say(); // I'm static.
// there is no way to directly access the inner function from here

Passing arguments

TODO: document this tutorial.