There's a pattern I really like, and it goes like this:
var myObj = function()
{
return {
f1: function()
{
// Some code...
},
f2: function()
{
// Some other code...
}
}
}();
I am not going to write about this pattern right now, but to mention an issues with the return bracket. Turns out that if I take the opening bracket '{' right after the 'return' one row down, then the whole thing breaks apart and JavaScript cannot understand it.
The reason for it is that while writing JavaScript one does not have to put a ; at the end of every line, so the statement 'return' is actually similar to 'return;', and it doesn't matter that the row below contains the beginning of an object to return.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment