javascript - Are anonymous function assignment variables locally available? -
i thought anonymous functions have no name
that's not case when assigned:
const foo = () => {}; console.log(foo.name); // expected "" got "foo"
that got me wondering whether variable name local anonymous function:
const fact = n => n > 0 ? n * fact(n - 1) : 1; // ^ // | // fact local variable?
if it's not local recursive functions fact
need travel scope chain. obviously, not major performance issue. nevertheless, i'm curious know whether function variable name local within anonymous function.
i'm curious know whether function variable name local within anonymous function.
no. case named function expressions (and it's not local variable there).
we need travel scope chain. obviously, not major performance issue.
it's not performance difference at all. scope chains static , doesn't matter performance in scope variable is.
i thought anonymous functions have no name that's not case when assigned.
yes, it's new es6 feature anonymous function expressions directly assigned variable .name
property set. however, has nothing scope.
Comments
Post a Comment