On Oct 29, 11:19 pm, gMinuses <gminu...@gmail.com> wrote: > But making map() functions work on hashes makes sense, so why rule > them out?
I'm not convinced. Is this the sort of usage, you are considering?: var newMap = function(obj, fn) { var options = $.extend( {}, obj); for (key in options) { options[key] = fn(options[key]); } return options; }; $(document).ready(function() { var obj = { url: "http://jquery.com/", success: function() {alert("Hurrah!");}, failure: function() {alert("Boohoo!");} }; var myInstrumentation = function(option) { if ($.isFunction(option)) { return function() { if (!this.count) this.count = 0; this.count++; option.call(this); } } else { return option; } }; var newObj = newMap(obj, myInstrumentation); newObj.success.call(newObj); newObj.failure.call(newObj); newObj.success.call(newObj); alert("Total calls: " + newObj.count); If so, then only a slight modification of the input object could cause real problems, e.g. var obj = { url: "http://jquery.com/", success: function() { this.helper(); alert("Hurrah!"); }, failure: function() { this.helper(); alert("Boohoo!"); }, helper: function() { // do something here } }; Note that with this new function, count is also incremented in the nested calls to the helper function. Any time an object maintains its own state, or your mapping function maintains its own, your code is at the mercy of the implementation of the object supplied. If there are only simple callback functions that don't call other functions in the object, you might not have problems, but in other cases, there could be problems. You can see these in action at http://scott.sauyet.com/Javascript/Demo/2009-10-29a/1/ and http://scott.sauyet.com/Javascript/Demo/2009-10-29a/2/ As I said, I'm not convinced. I think if you have a need for it, you can write your own extension quite easily, but I can't quite see something like this in the jQuery core. Cheers, -- Scott -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.