Rebuild update vendors, minified files, and adjust README.md changelog.

Former-commit-id: a01567b3d8e88da0cb20e12c864703e633b86fc6
This commit is contained in:
John-David Dalton
2012-12-03 22:40:28 -08:00
parent bb187db49d
commit ed8746df77
12 changed files with 119 additions and 91 deletions

View File

@@ -61,10 +61,10 @@ $(document).ready(function() {
test("flatten", function() {
var list = [1, [2], [3, [[[4]]]]];
equal(JSON.stringify(_.flatten(list)), '[1,2,3,4]', 'can flatten nested arrays');
equal(JSON.stringify(_.flatten(list, true)), '[1,2,3,[[[4]]]]', 'can shallowly flatten nested arrays');
deepEqual(_.flatten(list), [1,2,3,4], 'can flatten nested arrays');
deepEqual(_.flatten(list, true), [1,2,3,[[[4]]]], 'can shallowly flatten nested arrays');
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
equal(JSON.stringify(result), '[1,2,3,4]', 'works on an arguments object');
deepEqual(result, [1,2,3,4], 'works on an arguments object');
});
test("without", function() {

View File

@@ -37,7 +37,7 @@ $(document).ready(function() {
var newBoundf = new Boundf();
equal(newBoundf.hello, undefined, "function should not be bound to the context, to comply with ECMAScript 5");
equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context");
ok(newBoundf instanceof Boundf && newBoundf instanceof F, "a bound instance is an instance of the bound and original function");
ok(newBoundf instanceof F, "a bound instance is an instance of the original function");
});
test("bindAll", function() {
@@ -165,6 +165,31 @@ $(document).ready(function() {
}, 400);
});
asyncTest("throttle triggers trailing call after repeatedly invoked", 2, function() {
var actual;
var counter = 0;
var limit = 80;
var incr = function(){ counter++; };
var throttledIncr = _.throttle(incr, 32);
var stamp = new Date;
while ((new Date - stamp) < limit) {
throttledIncr();
}
_.delay(function() {
actual = counter + 2;
throttledIncr();
throttledIncr();
}, 64);
_.delay(function() {
equal(counter, actual);
start();
}, 128);
ok(counter > 1);
});
asyncTest("debounce", 1, function() {
var counter = 0;
var incr = function(){ counter++; };

File diff suppressed because one or more lines are too long

View File

@@ -573,22 +573,20 @@
// optionally). Binding with arguments is also known as `curry`.
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
// We check for `func.bind` first, to fail fast when `func` is undefined.
_.bind = function bind(func, context) {
_.bind = function(func, context) {
var args, bound;
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
if (!_.isFunction(func)) throw new TypeError;
var args = slice.call(arguments, 2);
var bound = function() {
args = slice.call(arguments, 2);
return bound = function() {
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
var result = func.apply(this, args.concat(slice.call(arguments)));
if (Object(result) === result) return result;
return this;
};
if (func && func.prototype) {
ctor.prototype = func.prototype;
bound.prototype = new ctor;
var self = new ctor;
ctor.prototype = null;
}
return bound;
var result = func.apply(self, args.concat(slice.call(arguments)));
if (Object(result) === result) return result;
return self;
};
};
// Bind all of an object's methods to that object. Useful for ensuring that
@@ -640,6 +638,7 @@
args = arguments;
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
} else if (!timeout) {
@@ -1075,7 +1074,7 @@
// Useful for temporary DOM ids.
var idCounter = 0;
_.uniqueId = function(prefix) {
var id = idCounter++;
var id = '' + ++idCounter;
return prefix ? prefix + id : id;
};