lib3k 0.1a

python.js

Summary

No overview generated for 'python.js'


Method Summary
static Object map(func, list)
          
static Object range(start, stop, step)
          

//
// Copyright (c) 2006 Tobi Schäfer
// Alle Rechte vorbehalten. All rights reserved.
//
// $Revision$
// $Author$
// $Date$
//

function range(start, stop, step) {
   var result = [];
   if (!step) {
      step = 1;
      if (!stop) {
         stop = start - 1;
         start = 0;
      }
   }
   for (var i=start; i<=stop; i+=step) {
      result.push(i);
   }
   return result;
}

function map(func, list) {
   for (var i in list)
      list[i] = func(list[i]);
   return list;
}

Number.prototype.combine = function(operator) {
   var self = this;
   switch (operator.constructor) {
      case Number:
         return self * operator;
      case String:
         var result = new StringBuffer(self * operator.length);
         for (var i in range(self))
            result.append(operator);
         return new String(result);
      case Date:
         return new Date(self * operator);
      case Array:
      case Object:
         return Object.prototype.combine.call(this, operator);
   }
   return operator;
};

Number.prototype.dontEnum("combine");

String.prototype.combine = function(operator) {
   if (operator.constructor != String)
      return Object.prototype.combine.call(this, operator);
   return this + operator;
};

String.prototype.dontEnum("combine");

Array.prototype.combine = function(operator) {
   if (operator.constructor != Array)
      return Object.prototype.combine.call(this, operator);
   for (var i in range(Math.min(this.length, operator.length)))
      this[i] = this[i].combine(operator[i]);
   return this;
};

Array.prototype.dontEnum("combine");

Object.prototype.combine = function(operator) {
   var self = this;
   switch (operator.constructor) {
      case Number:
      case String:
         return operator.combine(self);
         
      case Array:
      case Object:
         switch (self.constructor) {
            case Array:
               var value, counter = 0;
               for (var i in operator) {
                  if (value = self[counter])
                     self[counter] = value.combine(operator[i]);
                  counter += 1;
               }
               return self;
               
            case Object:
               var value, counter = 0;
               for (var i in self) {
                  if (value = operator[counter])
                     self[i] = self[i].combine(value);
                     counter += 1;
               }
               return self;
               
            default:
               return map(function(e) {
                  return self.combine(e);
               }, operator);
         }
   }
   return self;
}

Object.prototype.dontEnum("combine");

Object.prototype.getKeys = function() {
   var result = [];
   for (var i in this)
      result.push(i);
   return result;
};

Object.prototype.dontEnum("getKeys");

Object.prototype.getValues = function() {
   var result = [];
   for (var i in this)
      result.push(this[i]);
   return result;
};

Object.prototype.dontEnum("getValues");

Object.prototype.getItems = function() {
   var result = [];
   for (var i in this)
      result.push([i, this[i]]);
   return result;
};

Object.prototype.dontEnum("getItems");

HopObject.prototype.loop = function(callback, start, stop, step) {
   if (!start)
      start = this.size();
   for (var i in range(start, stop, step)) {
      callback.call(this.get(Number(i)), i);
   }
   return;
};

lib3k 0.1a

Documentation generated by JSDoc on Sun Mar 4 00:51:24 2007