2

This is probably a stupid question, but I am hoping to find out from someone who knows better than I do, is there any difference between the following function declarations within a class?

someFunction: function (obj) {};

and

someFunction: function someFunction (obj) {};
1
  • first its anonimous, the second are named, there is quite different, so its unclear what do you want know, please add details of your question Commented Jun 24, 2014 at 19:24

1 Answer 1

4

Setting a name on an anonymous function allows you to use that name inside the function.

For example:

var funcs = {
    someFunction: function someFunction(obj){
        // you can access 'someFunction' in here
    },
    otherFunction: function(obj){
        // you cannot access 'otherFunction',
        // you'd need to do 'funcs.otherFunction'
    }
};
Sign up to request clarification or add additional context in comments.

13 Comments

if you give it a name, is really still anonymous?
@JonathanWilson: I'm not sure how you refer to it, but the function's "name" will only exist inside the function itself, so I guess it's still "anonymous". I don't really know :)
I agree with you overall. I'm just being pedantic I guess ;)
You may be right though. Not sure if it still counts as "anonymous".
Note that you would need a , between someFunction and otherFunction, and a ; at the end would be recommended.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.