Reputation: 14287
When should I do this:
$.test = {
foo: function() {
this.bar();
},
bar: function() {
}
}
$.test.foo();
And when should I do this?
$.testFoo = function() {
$.testBar();
}
$.testBar = function() {
}
$.testFoo();
Upvotes: 3
Views: 70
Reputation:
The following defines an object with two methods
$.test = {
foo: function() {
this.bar();
},
bar: function() {
}
}
$.test.foo();
This just defines two functions
$.testFoo = function() {
$.testBar();
}
$.testBar = function() {
}
$.testFoo();
If you want to associate the two functions with each other then use an object. If the functions do two completely different things then just define separate functions
Upvotes: 6