Permalink
Browse files

Don't iterate over arguments array using for...in.

Might work fine in node.js, but order isn't guaranteed, which could lead
to some weird bugs, since order of curried function's arguments would be
silently modified. Also, just plain-out fails to run in some browsers
(e.g., Safari 5.1).

Also, change the coding style completely, since I like my curly braces.
  • Loading branch information...
1 parent 1a1dd22 commit 4a86a04cbae2b199014e2b5c2dff50317c35cc77 @aperiodic aperiodic committed Sep 14, 2011
Showing with 23 additions and 19 deletions.
  1. +23 −19 curry.js
View
@@ -1,29 +1,33 @@
-module.exports = curry
+module.exports = curry;
-function curry (){
- var left, right, func, self
+function curry () {
+ var left, right, func, self;
- for(key in arguments){
- var value = arguments[key]
+ for (var i = 0; i < arguments.length; i++) {
+ var value = arguments[key];
- if(!right && Array.isArray(value))
- if (!func)
- left = value
- else
- right = value
- else if (!func && typeof value === 'function')
- func = value
- else
- self = value
+ if (!right && Array.isArray(value)) {
+ if (!func) {
+ left = value;
+ } else {
+ right = value;
+ }
+ } else if (!func && typeof value === 'function') {
+ func = value;
+ } else {
+ self = value;
+ }
}
- return function (){
- return func.apply(self,append([].concat(left || []),arguments).concat(right || []))
+
+ return function () {
+ return func.apply(self,append([].concat(left || []),arguments).concat(right || []));
}
}
-function append (a,args){
- for (i in args)
+function append (a, args) {
+ for (var i = 0; i < arguments.length; i++) {
a.push(args[i])
- return a
+ }
+ return a;
}
/*
call styles:

0 comments on commit 4a86a04

Please sign in to comment.