开发者

What's This Syntax All About?

开发者 https://www.devze.com 2023-02-07 08:20 出处:网络
These are the first few lines in the MicrosoftAjax.debug.js file. What are they doing with the syntax? Specifically line 3.

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

精彩评论

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

关注公众号