Widgets walk a fine line between abstractions and implementations. Implementation, in this case, is a practical solution chosen to perform a given function. The problems with widgets occur when the widget author walks too far in one direction, or worse, walks an outward spiral covering both directions. Both choices lead to script bloat and complexity thats hard to manage. You no longer have a simple solution for a defined problem, you have a complex solution for a variety of problems. The good news is there are ways to avoid both the bloat and complexity.
He details the world of extending classes in JavaScript, and then gets to actsAsAspect, which lets you get AOP-y via before, after, and around advice.
PLAIN TEXT
JAVASCRIPT:
1.
2.
function actsAsAspect(object) {
3.
object.yield = null;
4.
object.rv = { };
5.
object.before = function(method, f) {
6.
var original = eval("this." + method);
7.
this[method] = function() {
8.
f.apply(this, arguments);
9.
return original.apply(this, arguments);
10.
};
11.
};
12.
object.after = function(method, f) {
13.
var original = eval("this." + method);
14.
this[method] = function() {
15.
this.rv[method] = original.apply(this, arguments);
16.
return f.apply(this, arguments);
17.
}
18.
};
19.
object.around = function(method, f) {
20.
var original = eval("this." + method);
21.
this[method] = function() {
22.
this.yield = original;
23.
return f.apply(this, arguments);
24.
}
25.
};
26.
}
27.
As someone who has worked with AOP via AspectJ and other libraries, it makes me a bit queasy to consider this AOP. One of the key elements is the pointcut language, which is very primitive here.
I do like the conclusion though:
While this is a rather convoluted example, the premise is solid. When creating widgets, don’t over abstract, and avoid hacking when possible. Even though we jazzed up our widget in the end, it’s original purpose is still intact and we added no additional overhead to it. Those who want ”more cowbell” can get it by plugging-in the additional scripts.
source: ajaxian
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.
Be the first ... |Add your comment.
Your Comment ...
Name (required)
Email (required, hidden)
Website
