• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Creating extensible Prototype Widgets ...

Justin Palmer has written about avoiding bloat in widgets with respect to Prototype.

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

 View Full Story.
Posted at 08:30:25 am | Permalink | Posted in Javascript  

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


Top Stuff

e-messenger

MessengerFX

eBuddy

ILoveIM

AIM Express

Top 20 Ruby CMS


Our Partners

Facebook Applications

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines

Stock Exchange Chat


About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (111)
  • Articles (85)
  • Bookmarking (35)
  • Calendar (19)
  • Chat (39)
  • ColdFusion (3)
  • CSS (41)
  • Email (23)
  • Facebook (23)
  • Flash (15)
  • Games (6)
  • Google (28)
  • Html (14)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (36)
  • Javascript (171)
  • JSON (21)
  • Perl (2)
  • PHP (88)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (1)
  • Ruby (10)
  • Storage (4)
  • Toolkits (90)
  • Tutorials (199)
  • UI (12)
  • Utilities (167)
  • Web2.0 (13)
  • XmlHttpRequest (20)
  • YUI (4)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange