Permalink
Browse files

use Array.apply(null, arguments)

  • Loading branch information...
tj committed Apr 19, 2012
1 parent 37b6e95 commit 66c8033cdd5d7a7ceee785e970bff7e08d943482
Showing with 1 addition and 1 deletion.
  1. +1 −1 index.js
View
@@ -55,7 +55,7 @@ exports.__defineGetter__('currentNamespace', function(){
(express.router || express.Router).methods.concat('del').forEach(function(method){
var orig = app[method];
exports[method] = function(){
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.apply(null, arguments)

This comment has been minimized.

Show comment Hide comment
@mikepb

mikepb Apr 24, 2012

Though it would not be a valid argument to the wrapped functions, Array.apply() doesn't work with a single number argument:

function toArray(){
  return Array.apply(null, arguments);
}

console.dir(toArray(2)); // returns array of undefined of length 2
console.dir(toArray(3)); // returns array of undefined of length 3
@mikepb

mikepb Apr 24, 2012

Though it would not be a valid argument to the wrapped functions, Array.apply() doesn't work with a single number argument:

function toArray(){
  return Array.apply(null, arguments);
}

console.dir(toArray(2)); // returns array of undefined of length 2
console.dir(toArray(3)); // returns array of undefined of length 3

This comment has been minimized.

Show comment Hide comment
@tj

tj Apr 25, 2012

Member

ah right it takes a length too. fine for this use-case but I'll revert anyway

@tj

tj Apr 25, 2012

Member

ah right it takes a length too. fine for this use-case but I'll revert anyway

This comment has been minimized.

Show comment Hide comment
@mikepb

mikepb Apr 25, 2012

yes, oh all the fun ways to use Array

@mikepb

mikepb Apr 25, 2012

yes, oh all the fun ways to use Array

, path = args.shift()
, fn = args.pop()
, self = this;

0 comments on commit 66c8033

Please sign in to comment.