开发者

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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜