Created
August 25, 2008 10:14
-
-
Save cooldaemon/7059 to your computer and use it in GitHub Desktop.
Extended Mochikit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var create_class = function () { | |
var m = MochiKit.Base; | |
var iter = MochiKit.Iter; | |
var new_func = function () { | |
if (typeof this._new !== 'function') { | |
return; | |
} | |
this._new.apply(this, arguments); | |
}; | |
iter.forEach( | |
arguments, | |
m.partial(m.update, new_func.prototype) | |
); | |
return new_func; | |
}; | |
var Lazy = function (func) { | |
var m = MochiKit.Base; | |
this.func = func; | |
this.arg_count = m.isUndefinedOrNull(arguments[1]) ? 0 : arguments[1]; | |
}; | |
var hole = {}; | |
var lazy = function (func, arg_count) { | |
return new Lazy(func, arg_count); | |
}; | |
var my_partial = function (func) { | |
var m = MochiKit.Base; | |
var it = MochiKit.Iter; | |
var base_args = m.extend(null, arguments, 1); | |
return function () { | |
var args = arguments; | |
args.shift = Array.prototype.shift; | |
var new_args = []; | |
it.forEach(base_args, function (arg) { | |
if (arg !== hole && !(arg instanceof Lazy)) { | |
new_args.push(arg); | |
return; | |
} | |
if (arg == hole) { | |
if (!m.isUndefinedOrNull(args[0])) { | |
new_args.push(args.shift()); | |
} | |
return; | |
} | |
var lazy_args = []; | |
for (var count = 0; count < arg.arg_count; count++) { | |
if (m.isUndefinedOrNull(args[0])) { | |
break; | |
} | |
lazy_args.push(args.shift()); | |
} | |
new_args.push(arg.func.apply(this, lazy_args)); | |
}); | |
it.forEach(args, function (arg) { | |
new_args.push(arg); | |
}); | |
func.apply(this, new_args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment