jashkenas--coffeescript/lib/utilities.js

27 lines
1.3 KiB
JavaScript
Raw Normal View History

(function(){
var utilities;
if (!((typeof process !== "undefined" && process !== null))) {
this.exports = this;
}
2010-03-30 20:14:07 +00:00
exports.utilities = (function() {
utilities = function utilities() { };
utilities.key = function key(name) {
return "__" + name;
};
2010-03-30 20:14:07 +00:00
utilities.format = function format(key, tab) {
return "" + (utilities.key(key)) + " = " + (utilities.functions[key].replace(/\n/g, "\n" + tab) || 'undefined');
2010-03-30 20:14:07 +00:00
};
utilities.dependencies = {
bind: ['slice']
2010-03-30 20:14:07 +00:00
};
utilities.functions = {
extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}",
2010-03-30 22:49:55 +00:00
bind: "function(func, obj, args) {\n return function() {\n return func.apply(obj || {}, args ? args.concat(" + (utilities.key('slice')) + ".call(arguments, 0)) : arguments);\n };\n}",
2010-03-30 20:14:07 +00:00
range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}",
hasProp: 'Object.prototype.hasOwnProperty',
slice: 'Array.prototype.slice'
2010-03-30 20:14:07 +00:00
};
return utilities;
}).call(this);
})();