Web Info & Tutorials

August 15th, 2007

LAZY FUNCTION DEFINITION PATTERN

Peter Michaux has written about the Lazy Function Definition Pattern.

His article takes you down the path of implementing a simple problem:

Write a function foo that returns a Date object that holds the time that foo was first called.

After critiquing 3 iterations he ends up with:

JAVASCRIPT:
  1.  
  2. var foo = function() {
  3.     var t = new Date();
  4.     foo = function() {
  5.         return t;
  6.     };
  7.     return foo();
  8. };
  9.  

He then uses the technique to implement getScrollX, and to talk about how you can use defineGetter in certain browsers to simulate lazy definition for properties that aren’t functions.

August 15th, 2007

BUILDING AN EVENT-BASED AJAX APPLICATION

Dojo has had a publish/subscribe system forever. With 0.9 it gets even better, and this writeup discusses how you can wire up your Ajax application using pub/sub.

If you have an application that uses devices like deferred loading, or “parse on demand”, wrapping it with an initializer helps keep it that way.

The final code example is:

JAVASCRIPT:
  1.  
  2. acme.topic = function(){
  3.         // current topic argument hash map
  4.         this.current = {};
  5. };
  6.  
  7. dojo.extend(acme.topic, {
  8.         subscribe: function(topic, scope, method, acceptNull){
  9.  
  10.                 var hdl = dojo.subscribe(topic, scope, method)
  11.  
  12.                 //Initializer - called only once, on subscribe
  13.                 if(acceptNull || this.current[topic]){
  14.                         // Converting arg to a non-array if it is not a length> 1
  15.                         var a = this.current[topic];
  16.                         var arg = (a == null)null : (a.length == 1) ? a[0] : a;
  17.  
  18.                         //NOTE! Only accepting string methods
  19.                         scope[method].call(scope, arg);
  20.                 }
  21.                 return hdl;
  22.         },
  23.  
  24.         publish: function(topic, args){
  25.                 dojo.publish(topic, args);
  26.                 // Store published arg, in the event a subscribe is called later
  27.                 this.current[topic] = args;
  28.         },
  29.  
  30.         unsubscribe: function(handle){
  31.                 // Pass-through. Could be called directly.
  32.                 dojo.unsubscribe(handle);
  33.         }
  34. })
  35.  
August 15th, 2007

GOOD PRACTICES FOR ACTIVEX UPDATES

Over on the IEBlog they are chatting most Good Practices for ActiveX Updates.

They came up with:

  1. Add spotting system to your ActiveX curb to analyse for updates
  2. Build an update workable and start it discover of Protected Mode to establish the update
  3. Give modify users and IT Admins the pick to attain updates

The accord has also additional others much as “calling WinVerifyTrust before executing your raise binary” and how to switch discover a newborn edition in the streaming covering without asking for a application restart.