Sam
Sam

Reputation: 15770

What's This Syntax All About?

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) { 

Upvotes: 3

Views: 172

Answers (1)

SLaks
SLaks

Reputation: 888177

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)

Upvotes: 2

Related Questions