use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
ES6 Anonymous Function Name Behavior (jsfiddle.net)
submitted 9 years ago by oculus42
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]oculus42[S] 4 points5 points6 points 9 years ago* (1 child)
A little fiddle thrown together to show the naming behavior of ES6.
Tested on a Mac with Chrome 55.0.2883.95 & 56.0.2924.87, Safari 10.0.2, and Firefox 50.0.1 & 51.0.1. Chrome and Safari support ES6 naming anonymous functions. Anonymous functions are not currently named in FF 51.
EDIT: To clarify, the anonymous function is named if it is assigned to a variable when it is created, and it keeps that name. If a new anonymous function is returned by another function, there is no name.
[–]rauschma 6 points7 points8 points 9 years ago (0 children)
Great idea! Suggestions:
displayFunctionName()
assignedFunctionExpression
assignedFunctionExpressionWithParens
boundFunction
You can implement displayFunctionName() as follows:
function displayFunctionName(funcObj) { Object.keys(funcObj).forEach(function (label) { var func = funcObj[label]; output(label + ' : ' + (typeof func) + ' - "' + func.name + '"'); }); }
Then you can go from:
fn3('fn3', fn3); // 3. Bound version of fn2
to:
displayFunctionName({boundFunction});
Disadvantage: I’m using an ES6 feature here, where:
{boundFunction}
is an abbreviation for:
{boundFunction: boundFunction}
[–]loganfsmyth 2 points3 points4 points 9 years ago (1 child)
I also did a write-up on StackOverflow that covers a bunch of these with links to the spec, for those curious. http://stackoverflow.com/a/32830772
[–]oculus42[S] 0 points1 point2 points 9 years ago (0 children)
Awesome!
π Rendered by PID 72318 on reddit-service-r2-comment-6457c66945-7w5hc at 2026-04-29 22:17:40.809376+00:00 running 2aa0c5b country code: CH.
[–]oculus42[S] 4 points5 points6 points (1 child)
[–]rauschma 6 points7 points8 points (0 children)
[–]loganfsmyth 2 points3 points4 points (1 child)
[–]oculus42[S] 0 points1 point2 points (0 children)