Skip to content

Conversation

@gyfnice
Copy link

@gyfnice gyfnice commented Jan 6, 2014

  • Name your functions. This is helpful for stack traces. //I don't understand why this can stack traces??

    // bad I think this is good,because very convenience.
    var log = function(msg) {
    console.log(msg);
    };

    // good I can't understand why is good? I think is not necessary js style.I hope you can explain this problem for me, I really confused. thank you.
    var log = function log(msg) {
    console.log(msg);
    };

@beginya
Copy link

beginya commented Jan 6, 2014

i sorry

2014/1/6 gyfnice [email protected]

Name your functions. This is helpful for stack traces. //I don't
understand why this can stack traces??

// bad I think this is good,because very convenience.
var log = function(msg) {
console.log(msg);
};

// good I can't understand why is good? I think is not necessary js
style.I hope you can explain this problem for me, I really confused. thank
you.
var log = function log(msg) {
console.log(msg);
};


You can merge this Pull Request by running

git pull https://github.com/gyfnice/javascript master

Or view, comment on, or merge it at:

#137
Commit Summary

  • good shoud replace better~~~
  • i know
  • about stack traces

File Changes

Patch Links:


Reply to this email directly or view it on GitHubhttps://github.com//pull/137
.

@jacobwgillespie
Copy link

This is good because the JS debugger will show the name of the function in the stacktrace if you follow the good style. Otherwise, it's just an anonymous function, which is harder to debug.

@gyfnice
Copy link
Author

gyfnice commented Jan 7, 2014

How I get information about the stacktrace?? can you give me a example?Comparison them with image,let me understand them distinction by image,very thanks

@hshoff
Copy link
Member

hshoff commented Jan 7, 2014

Here's a contrived example. Add an event handler to the <body> that calls a function when it's clicked. The important part is the call stack section in the chrome console debugger.

Anonymous function:

1

Named function:

2

Browsers are getting smarter though. Chrome will show the name of the assigned anonymous function expressions:

Named Function:

3

Anonymous function expression

4

Named Function expression

5

Hope that helps!

🍻

@hshoff hshoff closed this Jan 7, 2014
@gyfnice
Copy link
Author

gyfnice commented Jan 8, 2014

thanks @hshoff But as you said,Browsers are getting smarter though.why should we make an unnecessary things that To add the name of the function expression. I still felt unnecessary

@hshoff
Copy link
Member

hshoff commented Jan 8, 2014

This is one of those things that we've found helpful for us. It might not be necessary for everyone. Feel free to fork the style guide and update it to match the style of you and your team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants