Simply said, you need a callback, when you have to do one. This means,
you use another IO-related API that has a callback. Or a little more
elaborate, you need a callback when your code waits for something,
most times disc or network data, and thus the current flow logic
stalls until it arrives.
Hi All,
surprised to see many discussions about this, I'd say i learnt a lot:
1) return from loop
2) Array.some
3) return error instead of string
4) string is faster sometimes
all are very valuable, after evaluating my use case, I choose 2 and 4,
and reserve the rest for future use, very
If your user are not in a particular order, add to this: don't use an
array if there is no order, but a hash (object).
users = {};
e.g. with adding a user by: users[id] = {|somenewuserdata|};
In that case getting a new user is easy as:
exports.get_user = function(id, func) {
func(users[id]
This does bring out another topic, when we need a call back? Any
rule ? In this case the function wii be replaced with a database one
later, so it might have some IO.
On Mar 10, 11:49 pm, Axel Kittenberger axk...@gmail.com wrote:
If your user are not in a particular order, add to this: don't
oh, return is cool!
On Mar 9, 7:02 pm, Axel Kittenberger axk...@gmail.com wrote:
Many coders forget that you can use the return statement before the
end of the function. At least most people who finished some coding
course hardly ever do this. It usually simplifies many functions:
On Fri, Mar 9, 2012 at 10:36 AM, Roly Fentanes roly...@gmail.com wrote:
btw http://www.devthought.com/2011/12/22/a-string-is-not-an-error/
+1 for that, and while we are at it: The whole thread is a great example
why it is so important to use libraries like underscore's find:
For what it's worth, I was trying to minimize the changes to the function
and mainly demonstrate the use of the Array some method for iteration
that can benefit from stopping early.
---
R. Mark Volkmann
Object Computing, Inc.
On Mar 9, 2012, at 12:49 PM, Martin Wawrusch mar...@wawrusch.com
Though Errors definitely have their place, such as when an error
occurs, using an error for regular return codes during expected events
(assuming this function expects the look up to fail some times) is a
bit overkill, and horrible for performance.
http://jsperf.com/a-string-is-not-an-error
On