October 18th, 2006

javascript functions have a reference to themselves

I needed one of my javascript functions to be able to pass itself as a reference to another function, so I asked a couple friends if they knew if functions have a reference to themselves. They weren’t sure, so I googled it, and learned about arguments.callee:

callee is a property of the arguments local variable available within all function objects. […]

arguments.callee allows anonymous functions to refer to themselves, which is necessary for recursive anonymous functions.

The this keyword does not refer to the currently executing function. Use the callee property to refer to a function within the function body.

Just what I needed!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>