/*
==================================================================================================
  Lowland - JavaScript low level functions
  Copyright (C) 2012 Sebatian Fastner
==================================================================================================
*/

/**
 * #require(ext.sugar.Object)
 */

(function(window) {
  var hasPostMessage = !!window.postMessage;
  var slice = Array.prototype.slice;
  var timeouts = [];
  var messageName = "$$lowland-zero-timeout-message";
  
  var handleMessage = function() {
    if (event.source == window && event.data == messageName) {
      event.stopPropagation();
      if (timeouts.length > 0) {
        var timeout = timeouts.shift();
        
        timeout[0].apply(timeout[0], timeout[1]);
      }
    }
  };
  addEventListener("message", handleMessage, true);
  
  core.Main.addMembers("Function", {
    
    delay : function(time) {
      var func = this;
      setTimeout(function() {
        func.apply(func, slice.call(arguments, 1));
      }, time, slice.call(arguments, 1));
    },
    
    /**
     * Based upon work of http://dbaron.org/log/20100309-faster-timeouts
     */
    lazy : function(func) {
      timeouts.push([func, slice.call(arguments,1)]);
      postMessage(messageName, "*");
    }
  });

})(window);
@@ -900,20 +900,29 @@
 ion(time
+, context
 ) %7B%0A
-
       va
@@ -954,32 +954,45 @@
 imeout(function(
+context, args
 ) %7B%0A        func
@@ -1002,38 +1002,21 @@
 ply(
-func, slice.call(arguments, 1)
+context, args
 );%0A 
@@ -1028,16 +1028,25 @@
 %7D, time,
+ context,
  slice.c
@@ -1060,17 +1060,17 @@
 uments, 
-1
+2
 ));%0A    

Fix function.delay context setting