views:

24

answers:

1

Looking at the MS Ajax libraries, I notice they define object methods like so:

    addErrors: function Sys_Mvc_FormContext$addErrors(messages) {
    /// <param name="messages" type="Array" elementType="String">
    /// </param>
    if (!Sys.Mvc._validationUtil.arrayIsNullOrEmpty(messages)) {
        Array.addRange(this._errors, messages);
        this._onErrorCountChanged();
    }

Why the named function (Sys_Mvc_FormContext$addErrors(messages))? Why not just use:

addErrors: function(messages) {

I don't think I've seen this outside of MS Ajax...

+2  A: 

Naming function expressions is particularly useful for debugging purposes, so you can see in your call stack where you are exactly and all the actual function names.

Is also useful for recursion, since the Identifier of a function expression is only available within it's function body.

Note that there is a bug on the JScript implementation in which the identifier of a function expression leaks to its enclosing scope, hopefully this will get fixed some day...

Recommended article:

CMS
Awesome info. Thanks!!!
blech