4

These are the first few lines in the MicrosoftAjax.debug.js file.

What are they doing with the syntax? Specifically line 3.

Function.__typeName = 'Function';
Function.__class = true;
Function.createCallback = function Function$createCallback(method, context) { 
2
  • They're setting some properties on the Function constructor. What about it? Jan 28, 2011 at 0:38
  • btw the function literal in line 3 is a named function expression Jan 28, 2011 at 0:39

1 Answer 1

3

This is ordinary code which happens to have a $ character in a function name.

The expression function Function$createCallback(method, context) { ... } is a named function expression; it evaluates to a function named Function$createCallback.
Unlike many languages, the $ character is perfectly legal in a Javascript identifier (see jQuery), so this is a normal function with a somewhat unusual name.

The code assigns that function to create a createCallback property on the Function object.
(The property happens to be a function; Javascript functions are no different from variables)

2
  • What is the benefit of assigning a named vs. anonymous function to that property?
    – Jacob
    Jan 28, 2011 at 0:43
  • @Šime Vidas: I was just about to post that same article. :o)
    – user113716
    Jan 28, 2011 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.