Archive for the ‘Object’ Category

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.