javascript - What is the point of using a named function expression? -
this question has reply here:
var functionname = function() {} vs function functionname() {} 25 answers why utilize named function expressions? 3 answersi'm going through blog difference between function declarations , function expressions.
it gives these 2 examples. phone call first "anonymous function expression" , sec "named function expression."
// anonymous function look var = function(){ homecoming 3; } // named function look var b = function bar(){ homecoming 3; } i tested these 2 in chrome's js console , see following:
a() => 3 b() => 3 bar() => bar not defined my question is: in sec function look declaration, point of "bar"? in general, why 1 ever utilize named function expression?
some people prefer because if errors occur, functions have names. it's matter of preference , how have problem unnamed functions.
you don't see used in var declaration, instead when declaring callbacks:
callbackfunction(function success() { ... }, function fail() { ... }) that way know argument which, they're labelled, , if 1 of them fails precise indication of 1 broke.
javascript function-expression
No comments:
Post a Comment