use underscore.js

This commit is contained in:
Matthias Bartelmeß 2012-03-17 13:36:42 +01:00
parent 692e77b4e5
commit e559df18ce
13 changed files with 1069 additions and 113 deletions

View file

@ -33,56 +33,6 @@ function object(o)
f.prototype = o;
return new f();
}
function extend(obj, props)
{
for (var p in props)
{
obj[p] = props[p];
}
return obj;
}
var forEachImpl = function(fn){
for (var i = 0; i < this.length; i++)
{
var result = fn(this[i], i, this);
}
}
function mapImpl(fn)
{
var result = [];
for (var i = 0; i < this.length; i++)
{
if (fn) result.push(fn(this[i], i, this));
else result.push(this[i]);
}
return result;
}
// From underscore.js
var keysImpl =function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];
for (var key in obj) if (obj.hasOwnProperty(key)) keys.push(key);
return keys;
};
Array.prototype.forEach = Array.prototype.forEach || forEachImpl;
Array.prototype.each = Array.prototype.each || forEachImpl;
Array.prototype.map = Array.prototype.map || mapImpl;
Object.keys = Object.keys || keysImpl;
function isArray(testObject)
{
return testObject && typeof testObject === 'object' && !(testObject.propertyIsEnumerable('length')) && typeof testObject.length === 'number';
}
var userAgent = (((function () {return this;})().navigator || {}).userAgent || 'node-js').toLowerCase();
// Figure out what browser is being used (stolen from jquery 1.2.1)
@ -144,12 +94,9 @@ function htmlPrettyEscape(str)
}
var noop = function(){};
var identity = function(x){return x};
exports.isNodeText = isNodeText;
exports.object = object;
exports.extend = extend;
exports.isArray = isArray;
exports.browser = browser;
exports.getAssoc = getAssoc;
exports.setAssoc = setAssoc;
@ -157,4 +104,3 @@ exports.binarySearch = binarySearch;
exports.binarySearchInfinite = binarySearchInfinite;
exports.htmlPrettyEscape = htmlPrettyEscape;
exports.noop = noop;
exports.identity = identity;