Is there any advantage to defining a function name in "var new_function = function name () {};" in javascript?

I ran a program to modify some parts of javascript code when it listened to a var declaration as a function like this:

var some_function = function name(args){
//do stuff
};

The code itself works, but I'm just wondering if it will be possible to remove the "name" for all the functions that I find (this does not break it in another problem that parses my javascript), or if it could be any use for it that I don’t I see.

deleting "name":

var new_function = function(){/*do stuff*/};

Note: the source file, where it first appeared, was in jquery-1.6.4.js in:

jQuerySub.fn.init = function init( selector, context ) {
    if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
        context = jQuerySub( context );
    }

    return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
};

ty for any help in advance :)

+5
source share
1 answer

name .

jQuery init , , , , .

:

anonymous functions on stack

Vs.

named functions on stack

, IE lt = 8 , , , :

var foo = function bar() {}; 

typeof bar; // "function" on IE
foo === bar; // false, two different objects

, , , , , :

jQuerySub.fn.init = (function () {
  function init( selector, context ) {
    //...
  }

  return init;
})();

, :

+6

All Articles