2008/5/14 Pat Nakajima <[EMAIL PROTECTED]>: > > I've started putting together a way to specify per-object before/after > callbacks for any method. Probably not something to go in core, but > maybe something that would be interesting to core contributors. > > There are some examples in a GitHub wiki (http://github.com/nakajima/ > nakatype/wikis/callbacks), but basically, you specify callbacks like > so: > > var someArray = [1,2,3]; > > Callbacks.add(someArray, { > before: { > push: function(entry) { > var msg = 'about to push ' + entry + ' on array: ' + > this.join(', '); > console.info(msg); > } > }, > > after: { > push: function(entry) { > var msg = 'just pushed ' + entry + ' on array: ' + > this.join(', '); > console.info(msg); > } > } > }); > > someArray.push(4); > > In addition to adding 4 to someArray, the above code snippet will log > to the console before and after. > > If anybody has any suggestions/criticisms/threats, please do share!
A very useful idea. How far is it from simple before/after callbacks to a full AOP implementation? Where I can see this being of instant use is the ability to develop a class with no logging/diagnostics from day 1 and have a drop-in before/after logger which wouldn't upset the main class. Rather than having to name the methods, it would be great to be able to wildcard/regex them ( /[sg]et.+/ for example) as well as allowing all with an exclude mechanism (allow the high use methods to NOT be logged). I used to do Delphi development for a Point of Sale system. One of the issues that we had was the user would say the calculation was wrong. By using a plugin we could effectively record all the values of all the calculations and the source of the values and produce a report of any calculation. Remove the plugin and the app did nothing. All the hooking and recording was in the plugin. This was useful especially when you are converting costs with markups for bulk quantities converted between buying and selling units. It is in keeping with the "unobtrusive" nature of much JS code. I think the callback handler should be available as an extension (like the deprecated.js one is). So, officially supported/recognised, but not built-in as standard. Maybe amend the rake dist process to allow those with the skills to build their own prototype.js with the required extensions built in. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---