/* px.core */

Function.prototype.bind = function() {
  /* call 'func.bind(obj)' to create wrapper w/ 'this' bound to 'obj'
   * call 'func.bind(obj, a, b)' to create wrapper w/ 'this' bound to 'obj', and two arguments prepended
   * call 'func.bind(undefined, a,b)' to create wrapper w/ 'this' left unbound, and two arguments prepended
   * 'func.bind(undefined)' returns the original function
   */
  if (arguments[0] === undefined){
     if(arguments.length<2)
        return this;
     var func = this;
     var args = $.makeArray(arguments).slice(1);
     return function() { return func.apply(this, args); };
  }else{
     var func = this;
     var obj = arguments[0];
     if(arguments.length<2)
         return function() { return func.apply(obj); }
     var args = $.makeArray(arguments).slice(1);
     return function() { return func.apply(obj, args); };
  }
}

