function.js: rename private 'combine' method to 'update', add a private 'merge' methos.

This commit is contained in:
Tobie Langel 2008-10-01 01:36:03 +02:00
parent 3a93b6ccae
commit d9087c26a9
1 changed files with 20 additions and 14 deletions

View File

@ -1,12 +1,17 @@
Object.extend(Function.prototype, (function() {
var slice = Array.prototype.slice;
function combine(array, args) {
function update(array, args) {
var arrayLength = array.length, length = args.length;
while (length--) array[arrayLength + length] = args[length];
return array;
}
function merge(array, args) {
array = slice.call(array, 0);
return update(array, args);
}
function argumentNames() {
var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1]
.replace(/\s+/g, '').split(',');
@ -17,16 +22,16 @@ Object.extend(Function.prototype, (function() {
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
var __method = this, args = slice.call(arguments, 1);
return function() {
var combinedArgs = combine(args.clone(), arguments);
return __method.apply(context, combinedArgs);
var a = merge(args, arguments);
return __method.apply(context, a);
}
}
function bindAsEventListener(context) {
var __method = this, args = slice.call(arguments, 1);
return function(event) {
var combinedArgs = combine([event || window.event], args);
return __method.apply(context, combinedArgs);
var a = update([event || window.event], args);
return __method.apply(context, a);
}
}
@ -34,28 +39,29 @@ Object.extend(Function.prototype, (function() {
if (!arguments.length) return this;
var __method = this, args = slice.call(arguments, 0);
return function() {
var combinedArgs = combine(args.clone(), arguments);
return __method.apply(this, combinedArgs);
var a = merge(args, arguments);
return __method.apply(this, a);
}
}
function delay(timeout) {
var __method = this, args = slice.call(arguments, 1);
var __method = this, args = slice.call(arguments, 1);
timeout = timeout * 1000
return window.setTimeout(function() {
return __method.apply(__method, args);
}, timeout * 1000);
}, timeout);
}
function defer() {
var args = combine([0.01], arguments);
var args = update([0.01], arguments);
return this.delay.apply(this, args);
}
function wrap(wrapper) {
var __method = this;
return function() {
var combinedArgs = combine([__method.bind(this)], arguments);
return wrapper.apply(this, combinedArgs);
var a = update([__method.bind(this)], arguments);
return wrapper.apply(this, a);
}
}
@ -63,8 +69,8 @@ Object.extend(Function.prototype, (function() {
if (this._methodized) return this._methodized;
var __method = this;
return this._methodized = function() {
var combinedArgs = combine([this], arguments);
return __method.apply(null, combinedArgs);
var a = update([this], arguments);
return __method.apply(null, a);
};
}