> geolocator.getLatLng("Forest Park, St. Louis, MO", function(center) {
> displayMapAt(center, 14);
> });
To my eyes, that solution is just fine. I don't think I'll ever be swayed to believe that adding on layers of indirection to JavaScript code for the sake of "syntactic goodness" is rationally motivated by leading to more practical power for actually solving problems.
Agreed. If you're writing something in a web browser, use sane JavaScript. Every time I have done something "fancy" with a language, there has been a large hidden cost later on, be that complicated debugging sessions, new hire training, or unintended side effects. Terrible syntax/rewriting hacks in Rails are probably what convinced me that I do not like ruby. If you truly care about programmer efficiency, you probably want to look into cross compilers like Objective-J or parenscript.
You should probably assign an object to the underscore, otherwise any argument which is undefined will match:
js> var _
js> _ == undefined
true
Just doing "var _ = {}" should be sufficient.
edit: however, this conflicts with Underscore.js (http://documentcloud.github.com/underscore/), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok
I actually did a === check for just that reason, since if you define _ = {}, then passing in a real object that is {} will also return true for _ == {}
geolocator.getLatLng("Forest Park, St. Louis, MO", displayMapAt);
Is better than this?
displayMapAt(geolocator.getLatLng("Forest Park, St. Louis, MO"));
That is, why is it more sensible for getLatLng to accept a callback function that will accept its result, when one can just pass its result to a function?
I expect the call to geolocator requires a network round-trip, with displayMapAt getting scheduled to be called when the result appears; meanwhile your code can do other things. (I'm not familiar with this API, though; I could be wrong.)
Another way to do this sort of thing, that might feel more composable: have geolocator.getLatLng() return a 'promise' object that will be asynchronously resolved.
WilliamLP|16 years ago
> displayMapAt(center, 14);
> });
To my eyes, that solution is just fine. I don't think I'll ever be swayed to believe that adding on layers of indirection to JavaScript code for the sake of "syntactic goodness" is rationally motivated by leading to more practical power for actually solving problems.
ynniv|16 years ago
mikeryan|16 years ago
Sometimes brevity isn't the right solution.
tlrobinson|16 years ago
edit: however, this conflicts with Underscore.js (http://documentcloud.github.com/underscore/), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok
youngnh|16 years ago
ubernostrum|16 years ago
scott_s|16 years ago
abecedarius|16 years ago
Another way to do this sort of thing, that might feel more composable: have geolocator.getLatLng() return a 'promise' object that will be asynchronously resolved.
unknown|16 years ago
[deleted]
mdemare|16 years ago
scott_s|16 years ago
jimbokun|16 years ago
Zak|16 years ago
tomjen2|16 years ago