Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'ecma5' of https://github.com/arthurschreiber/prototype

  • Loading branch information...
commit c4a9149df10abecd80ad695ea91ed3720cad858d 2 parents c22e224 + 1f569ae
@savetheclocktower savetheclocktower authored
View
4 src/prototype/ajax/responders.js
@@ -69,8 +69,8 @@
Ajax.Responders = {
responders: [],
- _each: function(iterator) {
- this.responders._each(iterator);
+ _each: function(iterator, context) {
+ this.responders._each(iterator, context);
},
/**
View
4 src/prototype/deprecated.js
@@ -156,10 +156,10 @@ Element.ClassNames.prototype = {
this.element = $(element);
},
- _each: function(iterator) {
+ _each: function(iterator, context) {
this.element.className.split(/\s+/).select(function(name) {
return name.length > 0;
- })._each(iterator);
+ })._each(iterator, context);
},
set: function(className) {
View
131 src/prototype/lang/array.js
@@ -447,19 +447,122 @@ Array.from = $A;
}
// Replaces a built-in function. No PDoc needed.
- function concat() {
- var array = slice.call(this, 0), item;
- for (var i = 0, length = arguments.length; i < length; i++) {
- item = arguments[i];
+ function concat(_) {
+ var array = [], items = slice.call(arguments, 0), item, n = 0;
+ items.unshift(this);
+ for (var i = 0, length = items.length; i < length; i++) {
+ item = items[i];
if (Object.isArray(item) && !('callee' in item)) {
- for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
- array.push(item[j]);
+ for (var j = 0, arrayLength = item.length; j < arrayLength; j++) {
+ if (j in item) array[n] = item[j];
+ n++;
+ }
} else {
- array.push(item);
+ array[n++] = item;
}
}
+ array.length = n;
return array;
}
+
+ function wrapNative(method) {
@jdalton
jdalton added a note

I think every method that's using wrapNative has the same arguments signature so that means you can avoid .apply and use .call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return function() {
+ if (arguments.length === 0) {
+ return method.call(this, Prototype.K);
+ } else if (arguments[0] === undefined) {
+ var args = slice.call(arguments, 1);
+ args.unshift(Prototype.K)
+ return method.apply(this, args);
+ } else {
+ return method.apply(this, arguments);
+ }
+ };
+ }
+
+ if (arrayProto.map) {
+ var map = wrapNative(Array.prototype.map);
+ } else {
+ function map(iterator) {
+ iterator = iterator || Prototype.K;
+ var results = [], context = arguments[1], n = 0;
+
+ for (var i = 0, length = this.length; i < length; i++) {
+ if (i in this) {
+ results[n] = iterator.call(context, this[i], i, this);
+ }
+ n++;
+ }
+ results.length = n;
+ return results;
+ }
+ }
+
+ if (arrayProto.filter) {
+ var filter = Array.prototype.filter;
+ } else {
+ function filter(iterator) {
+ if (!Object.isFunction(iterator)) { throw new TypeError(); }
+ var results = [], context = arguments[1], value;
+
+ for (var i = 0, length = this.length; i < length; i++) {
+ if (i in this) {
+ value = this[i];
+ if (iterator.call(context, value, i, this)) {
+ results.push(value);
+ }
+ }
+ }
+ return results;
+ }
+ }
+
+ if (arrayProto.some) {
+ var some = wrapNative(Array.prototype.some);
+ } else {
+ function some(iterator) {
+ iterator = iterator || Prototype.K;
+ var context = arguments[1];
+
+ for (var i = 0, length = this.length; i < length; i++) {
+ if (i in this && iterator.call(context, this[i], i, this)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ if (arrayProto.every) {
+ var every = wrapNative(Array.prototype.every);
+ } else {
+ function every(iterator) {
@jdalton
jdalton added a note

Function declarations in blocks is super gross.

@savetheclocktower Collaborator

I might change it before release.

@jdalton
jdalton added a note

Here is a note from ES5 spec:

NOTE Several widely used implementations of ECMAScript are known to support the use of FunctionDeclaration as a Statement. However there are significant and irreconcilable variations among the implementations in the semantics applied to such FunctionDeclarations. Because of these irreconcilable difference, the use of a FunctionDeclaration as a Statement results in code that is not reliably portable among implementations. It is recommended that ECMAScript implementations either disallow this usage of FunctionDeclaration or issue a warning when such a usage is encountered. Future editions of ECMAScript may define alternative portable means for declaring functions in a Statement context.

@jdalton
jdalton added a note

Also it will throw an error in strict mode in Chrome too.

@kangax Collaborator
kangax added a note

IIRC, latest FF actually throws when encountering FD in blocks while in strict mode.

@savetheclocktower Collaborator

FINE I'LL CHANGE IT

@kangax Collaborator
kangax added a note

HUZZAH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ iterator = iterator || Prototype.K;
+ var context = arguments[1];
+
+ for (var i = 0, length = this.length; i < length; i++) {
+ if (i in this && !iterator.call(context, this[i], i, this)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
+ if (arrayProto.reduce) {
+ // Keep a copy of the native reduce
+ var _reduce = arrayProto.reduce;
+ function inject(memo, iterator) {
+ iterator = iterator || Prototype.K;
+ var context = arguments[2];
+ // The iterator has to be bound, as Array.prototype.reduce
+ // always executes the iterator in the global context.
+ return _reduce.call(this, iterator.bind(context), memo, context);
+ }
+ } else {
+ var inject = Enumerable.inject;
+ }
Object.extend(arrayProto, Enumerable);
@@ -468,6 +571,18 @@ Array.from = $A;
Object.extend(arrayProto, {
_each: _each,
+
+ map: map,
@jdalton
jdalton added a note

While you are at the ES5 fixes might wanna spruce up Function#bind too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ collect: map,
+ select: filter,
+ filter: filter,
+ findAll: filter,
+ some: some,
+ any: some,
+ every: every,
+ all: every,
+ inject: inject,
+
clear: clear,
first: first,
last: last,
@@ -486,7 +601,7 @@ Array.from = $A;
// fix for opera
var CONCAT_ARGUMENTS_BUGGY = (function() {
return [].concat(arguments)[0][0] !== 1;
- })(1,2)
+ })(1,2);
if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
View
53 src/prototype/lang/enumerable.js
@@ -107,11 +107,8 @@ var Enumerable = (function() {
* has a method to do that for you.
**/
function each(iterator, context) {
- var index = 0;
try {
- this._each(function(value) {
- iterator.call(context, value, index++);
- });
+ this._each(iterator, context);
} catch (e) {
if (e != $break) throw e;
}
@@ -186,9 +183,9 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var result = true;
this.each(function(value, index) {
- result = result && !!iterator.call(context, value, index);
+ result = result && !!iterator.call(context, value, index, this);
if (!result) throw $break;
- });
+ }, this);
return result;
}
@@ -218,9 +215,9 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var result = false;
this.each(function(value, index) {
- if (result = !!iterator.call(context, value, index))
+ if (result = !!iterator.call(context, value, index, this))
throw $break;
- });
+ }, this);
return result;
}
@@ -251,8 +248,8 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var results = [];
this.each(function(value, index) {
- results.push(iterator.call(context, value, index));
- });
+ results.push(iterator.call(context, value, index, this));
+ }, this);
return results;
}
@@ -274,11 +271,11 @@ var Enumerable = (function() {
function detect(iterator, context) {
var result;
this.each(function(value, index) {
- if (iterator.call(context, value, index)) {
+ if (iterator.call(context, value, index, this)) {
result = value;
throw $break;
}
- });
+ }, this);
return result;
}
@@ -299,9 +296,9 @@ var Enumerable = (function() {
function findAll(iterator, context) {
var results = [];
this.each(function(value, index) {
- if (iterator.call(context, value, index))
+ if (iterator.call(context, value, index, this))
results.push(value);
- });
+ }, this);
return results;
}
@@ -345,8 +342,8 @@ var Enumerable = (function() {
this.each(function(value, index) {
if (filter.match(value))
- results.push(iterator.call(context, value, index));
- });
+ results.push(iterator.call(context, value, index, this));
+ }, this);
return results;
}
@@ -449,8 +446,8 @@ var Enumerable = (function() {
**/
function inject(memo, iterator, context) {
this.each(function(value, index) {
- memo = iterator.call(context, memo, value, index);
- });
+ memo = iterator.call(context, memo, value, index, this);
+ }, this);
return memo;
}
@@ -514,10 +511,10 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var result;
this.each(function(value, index) {
- value = iterator.call(context, value, index);
+ value = iterator.call(context, value, index, this);
if (result == null || value >= result)
result = value;
- });
+ }, this);
return result;
}
@@ -554,10 +551,10 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var result;
this.each(function(value, index) {
- value = iterator.call(context, value, index);
+ value = iterator.call(context, value, index, this);
if (result == null || value < result)
result = value;
- });
+ }, this);
return result;
}
@@ -592,9 +589,9 @@ var Enumerable = (function() {
iterator = iterator || Prototype.K;
var trues = [], falses = [];
this.each(function(value, index) {
- (iterator.call(context, value, index) ?
+ (iterator.call(context, value, index, this) ?
trues : falses).push(value);
- });
+ }, this);
return [trues, falses];
}
@@ -636,9 +633,9 @@ var Enumerable = (function() {
function reject(iterator, context) {
var results = [];
this.each(function(value, index) {
- if (!iterator.call(context, value, index))
+ if (!iterator.call(context, value, index, this))
results.push(value);
- });
+ }, this);
return results;
}
@@ -668,9 +665,9 @@ var Enumerable = (function() {
return this.map(function(value, index) {
return {
value: value,
- criteria: iterator.call(context, value, index)
+ criteria: iterator.call(context, value, index, this)
};
- }).sort(function(left, right) {
+ }, this).sort(function(left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
}).pluck('value');
View
4 src/prototype/lang/hash.js
@@ -93,12 +93,12 @@ var Hash = Class.create(Enumerable, (function() {
**/
// Our _internal_ each
- function _each(iterator) {
+ function _each(iterator, context) {
for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
- iterator(pair);
+ iterator.call(context, pair);
}
}
View
4 src/prototype/lang/range.js
@@ -107,10 +107,10 @@ var ObjectRange = Class.create(Enumerable, (function() {
this.exclusive = exclusive;
}
- function _each(iterator) {
+ function _each(iterator, context) {
var value = this.start;
while (this.include(value)) {
- iterator(value);
+ iterator.call(context, value);
value = value.succ();
}
}
View
124 test/unit/array_test.js
@@ -182,7 +182,35 @@ new Test.Unit.Runner({
this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
},
- testConcat: function(){
+ testConcat: function() {
+ var x = {};
+
+ this.assertIdentical(1, Array.prototype.concat.length);
+
+ this.assertEnumEqual([0, 1], [0, 1].concat());
+ this.assertIdentical(2, [0, 1].concat().length);
+
+ this.assertEnumEqual([0, 1, 2, 3, 4], [].concat([0, 1], [2, 3, 4]));
+ this.assertIdentical(5, [].concat([0, 1], [2, 3, 4]).length);
+
+ this.assertEnumEqual([0, x, 1, 2, true, "NaN"], [0].concat(x, [1, 2], true, "NaN"));
+ this.assertIdentical(6, [0].concat(x, [1, 2], true, "NaN").length);
+
+ this.assertEnumEqual([undefined, 1, undefined], [,1].concat([], [,]));
+ this.assertIdentical(3, [,1].concat([], [,]).length);
+ this.assertEnumEqual([1], Object.keys([,1].concat([], [,])));
+
+ // Check that Array.prototype.concat can be used in a generic way
+ x.concat = Array.prototype.concat;
+ this.assertEnumEqual([x], x.concat());
+ this.assertIdentical(1, x.concat().length);
+
+ // Checking an edge case
+ var arr = []; arr[2] = true;
+ this.assertEnumEqual([undefined, undefined, true], [].concat(arr));
+ this.assertIdentical(3, [].concat(arr).length);
+ this.assertEnumEqual([2], Object.keys([].concat(arr)));
+
var args = (function() { return [].concat(arguments) })(1, 2);
this.assertIdentical(1, args[0][0]);
},
@@ -191,5 +219,99 @@ new Test.Unit.Runner({
var sparseArray = [0, 1];
sparseArray[5] = 5;
this.assertEqual('[0, 1, 5]', sparseArray.inspect(), "Array#each should skip nonexistent keys in an array");
+ },
+
+ testMapGeneric: function() {
+ var result = Array.prototype.map.call({0:0, 1:1, length:2});
+ this.assertEnumEqual([0, 1], result);
+ },
+
+ testMap: function() {
+ this.assertEnumEqual([1,2,3], [1,2,3].map());
+ this.assertEnumEqual([2,4,6], [1,2,3].map(function(x) { return x * 2; }));
+
+ var x = [1,2,3,4];
+ delete x[1];
+ delete x[3];
+ this.assertEnumEqual([1, undefined, 3, undefined], x.map());
+ this.assertIdentical(4, x.map().length);
+
+ var traversed = [];
+ x.map(function(val) {
+ traversed.push(val);
+ });
+ this.assertEnumEqual([1, 3], traversed);
+ this.assertIdentical(2, traversed.length);
+ },
+
+ testFindAllGeneric: function() {
+ var result = Array.prototype.findAll.call({0:0, 1:1, length:2}, function(x) {
+ return x === 1;
+ });
+ this.assertEnumEqual([1], result);
+ },
+
+ testFindAll: function() {
+ this.assertEnumEqual([2, 4, 6], [1, 2, 3, 4, 5, 6].findAll(function(x) {
+ return (x % 2) == 0;
+ }));
+
+ var x = [1,2,3], traversed = [];
+ delete x[1];
+ x.findAll(function(val) { traversed.push(val); });
+ this.assertEnumEqual([1, 3], traversed);
+ this.assertIdentical(2, traversed.length);
+ },
+
+ testAnyGeneric: function() {
+ this.assert(Array.prototype.any.call({ 0:false, 1:true, length:2 }));
+ this.assert(!Array.prototype.any.call({ 0:false, 1:false, length:2 }));
+ },
+
+ testAny: function() {
+ this.assert(!([].any()));
+
+ this.assert([true, true, true].any());
+ this.assert([true, false, false].any());
+ this.assert(![false, false, false].any());
+
+ this.assert([1,2,3,4,5].any(function(value) {
+ return value > 2;
+ }));
+ this.assert(![1,2,3,4,5].any(function(value) {
+ return value > 5;
+ }));
+
+ var x = [1,2,3], traversed = [];
+ delete x[1];
+ x.any(function(val) { traversed.push(val); });
+ this.assertEnumEqual([1, 3], traversed);
+ this.assertIdentical(2, traversed.length);
+ },
+
+ testAllGeneric: function() {
+ this.assert(Array.prototype.all.call({ 0:true, 1:true, length:2 }));
+ this.assert(!Array.prototype.all.call({ 0:false, 1:true, length:2 }));
+ },
+
+ testAll: function() {
+ this.assert([].all());
+
+ this.assert([true, true, true].all());
+ this.assert(![true, false, false].all());
+ this.assert(![false, false, false].all());
+
+ this.assert([1,2,3,4,5].all(function(value) {
+ return value > 0;
+ }));
+ this.assert(![1,2,3,4,5].all(function(value) {
+ return value > 1;
+ }));
+
+ var x = [1,2,3], traversed = [];
+ delete x[1];
+ x.all(function(val) { traversed.push(val); return true; });
+ this.assertEnumEqual([1, 3], traversed);
+ this.assertIdentical(2, traversed.length);
}
});
View
149 test/unit/enumerable_test.js
@@ -24,6 +24,16 @@ new Test.Unit.Runner({
this.assertEqual('1, 3', results.join(', '));
},
+ "test #each passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.each(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ }, this);
+ },
+
testEachChaining: function() {
this.assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
this.assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
@@ -63,6 +73,19 @@ new Test.Unit.Runner({
}));
},
+ "test #any passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.any(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+
+ // Iterate over all values
+ return value > 5;
+ }, this);
+ },
+
testAll: function() {
this.assert([].all());
@@ -78,6 +101,19 @@ new Test.Unit.Runner({
}));
},
+ "test #all passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.all(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+
+ // Iterate over all values
+ return value > 0;
+ }, this);
+ },
+
testCollect: function() {
this.assertEqual(Fixtures.Nicknames.join(', '),
Fixtures.People.collect(function(person) {
@@ -87,6 +123,17 @@ new Test.Unit.Runner({
this.assertEqual(26, Fixtures.Primes.map().length);
},
+ "test #collect passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.collect(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value;
+ }, this);
+ },
+
testDetect: function() {
this.assertEqual('Marcel Molina Jr.',
Fixtures.People.detect(function(person) {
@@ -94,6 +141,19 @@ new Test.Unit.Runner({
}).name);
},
+ "test #detect passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.detect(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+
+ // Iterate over all values
+ return value > 5;
+ }, this);
+ },
+
testEachSlice: function() {
this.assertEnumEqual([], [].eachSlice(2));
this.assertEqual(1, [1].eachSlice(1).length);
@@ -125,6 +185,17 @@ new Test.Unit.Runner({
Fixtures.Z.findAll(prime).join(', '));
},
+ "test #findAll passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.findAll(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value > 5;
+ }, this);
+ },
+
testGrep: function() {
this.assertEqual('noradio, htonl',
Fixtures.Nicknames.grep(/o/).join(", "));
@@ -146,6 +217,17 @@ new Test.Unit.Runner({
this.assertEnumEqual(['|a', 'c|'], ['|a','b','c|'].grep('|'));
},
+ "test #grep passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.grep(/\d/, function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value;
+ }, this);
+ },
+
testInclude: function() {
this.assert(Fixtures.Nicknames.include('sam-'));
this.assert(Fixtures.Nicknames.include('noradio'));
@@ -191,6 +273,18 @@ new Test.Unit.Runner({
}));
},
+ "test #inject passes memo, value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.inject(0, function(memo, value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+
+ return memo + value;
+ }, this);
+ },
+
testInvoke: function() {
var result = [[2, 1, 3], [6, 5, 4]].invoke('sort');
this.assertEqual(2, result.length);
@@ -209,12 +303,34 @@ new Test.Unit.Runner({
this.assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
},
+ "test #max passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.max(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value;
+ }, this);
+ },
+
testMin: function() {
this.assertEqual(1, Fixtures.Z.min());
this.assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
this.assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
},
+ "test #min passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.min(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value;
+ }, this);
+ },
+
testPartition: function() {
var result = Fixtures.People.partition(function(person) {
return person.name.length < 15;
@@ -225,6 +341,17 @@ new Test.Unit.Runner({
this.assertEqual('noradio, Ulysses', result[1].join(', '));
},
+ "test #partition passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.partition(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value < 2;
+ }, this);
+ },
+
testPluck: function() {
this.assertEqual(Fixtures.Nicknames.join(', '),
Fixtures.People.pluck('nickname').join(', '));
@@ -240,6 +367,17 @@ new Test.Unit.Runner({
}).join(', '));
},
+ "test #reject passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.reject(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value < 2;
+ }, this);
+ },
+
testSortBy: function() {
this.assertEqual('htonl, noradio, sam-, Ulysses',
Fixtures.People.sortBy(function(value) {
@@ -247,6 +385,17 @@ new Test.Unit.Runner({
}).pluck('nickname').join(', '));
},
+ "test #sortBy passes value, index and collection to the iterator": function() {
+ var i = 0;
+ Fixtures.Basic.sortBy(function(value, index, collection) {
+ this.assertIdentical(Fixtures.Basic[i], value);
+ this.assertIdentical(i, index);
+ this.assertIdentical(Fixtures.Basic, collection);
+ i++;
+ return value;
+ }, this);
+ },
+
testToArray: function() {
var result = Fixtures.People.toArray();
this.assert(result != Fixtures.People); // they're different objects...
@jdalton

While you are at the ES5 fixes might wanna spruce up Function#bind too.

@jdalton

Function declarations in blocks is super gross.

@savetheclocktower

I might change it before release.

@jdalton

Here is a note from ES5 spec:

NOTE Several widely used implementations of ECMAScript are known to support the use of FunctionDeclaration as a Statement. However there are significant and irreconcilable variations among the implementations in the semantics applied to such FunctionDeclarations. Because of these irreconcilable difference, the use of a FunctionDeclaration as a Statement results in code that is not reliably portable among implementations. It is recommended that ECMAScript implementations either disallow this usage of FunctionDeclaration or issue a warning when such a usage is encountered. Future editions of ECMAScript may define alternative portable means for declaring functions in a Statement context.

@jdalton

Also it will throw an error in strict mode in Chrome too.

@kangax

IIRC, latest FF actually throws when encountering FD in blocks while in strict mode.

@savetheclocktower

FINE I'LL CHANGE IT

@kangax

HUZZAH

@jdalton

I think every method that's using wrapNative has the same arguments signature so that means you can avoid .apply and use .call.

Please sign in to comment.
Something went wrong with that request. Please try again.