Reputation: 572
I'm new in JavaScript.
I want to what's the difference between this
function aa() {
// code
}
function bb() {
// code
}
and this
var b = {
aa: function () {
//code
},
bb: function () {
//code
}
};
I know about the first, but I don't know about the other one.
What's it called and what's differences?
Upvotes: 0
Views: 48
Reputation: 298046
The first one creates two named functions: aa
and bb
.
The second one creates an object called b
that has two properties: aa
and bb
, both of which have anonymous functions as values.
They do different things, so you can't really say which one is "better".
Upvotes: 1