Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use array.(map|forEach)(fn, this) instead of array.(map|forEach)(fn.b…

…ind(this)).

With node 0.4.6 that's a 220% speed improvement (54% in Chrome 10) according to this test: http://jsperf.com/bindvsforeachwith2ndarg
  • Loading branch information...
commit 004ef0844b2d3fa4a267cc657c8352e94542242e 1 parent d13f12e
@papandreou papandreou authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 index.js
View
20 index.js
@@ -93,9 +93,9 @@ function builder (saw, xs) {
function () {
context.stack_ = [];
var args = [].slice.call(arguments);
- args.unshift.apply(args, bound.map((function (arg) {
+ args.unshift.apply(args, bound.map(function (arg) {
return arg === Seq ? this : arg
- }).bind(this)));
+ }, this));
cb.apply(this, args);
}, function () {
@@ -124,9 +124,9 @@ function builder (saw, xs) {
}
var cb_ = function () {
var args = [].slice.call(arguments);
- args.unshift.apply(args, bound.map((function (arg) {
+ args.unshift.apply(args, bound.map(function (arg) {
return arg === Seq ? this : arg
- }).bind(this)));
+ }, this));
cb.apply(this, args);
};
@@ -151,7 +151,7 @@ function builder (saw, xs) {
saw.next();
};
- [ 'seq', 'par' ].forEach((function (name) {
+ [ 'seq', 'par' ].forEach(function (name) {
this[name + '_'] = function (key) {
var args = [].slice.call(arguments);
@@ -173,7 +173,7 @@ function builder (saw, xs) {
this[name].apply(this, args);
};
- }).bind(this));
+ }, this);
this['catch'] = function (cb) {
if (context.error) {
@@ -285,7 +285,7 @@ function builder (saw, xs) {
};
[ 'forEach', 'seqEach', 'parEach', 'seqMap', 'parMap' ]
- .forEach((function (name) {
+ .forEach(function (name) {
this[name + '_'] = function (cb) {
this[name].call(this, function () {
var args = [].slice.call(arguments);
@@ -293,11 +293,11 @@ function builder (saw, xs) {
cb.apply(this, args);
});
};
- }).bind(this))
+ }, this)
;
['push','pop','shift','unshift','splice']
- .forEach((function (name) {
+ .forEach(function (name) {
this[name] = function () {
context.stack[name].apply(
context.stack,
@@ -306,7 +306,7 @@ function builder (saw, xs) {
saw.next();
return this;
};
- }).bind(this))
+ }, this)
;
this.extend = function (xs) {
Please sign in to comment.
Something went wrong with that request. Please try again.