Archive for the ‘Function’ Category

Functions as arguements

Friday, July 28th, 2006

Slash7 has posted the slides from their brilliant Javascript Boot Camp Tutorial talk at OSCON. 108 pages of pure JavaScript love. One thing I just learnt, on page 36, is that you can pass a function as an arguement into another function. That function can then call the arguement function. Sounds weird but that is pretty amazing if you ask me.

Functional objects

Wednesday, June 7th, 2006

It is obvious when you think about it but functions are objects in JavaScript. So a function can have members. e.g.
var f = function()
{
    return 2;
}

f.g = function(x)
{
    return x + f();
}

If I ran f.g(5); I’d get back 7.