0

ATT, is there any difference between below implements?
1.

var a = [];
f = function(){
    a = [].concat(a,[].slice.call(arguments));
}

2.

var a = [];
f = function(){
    a = Array.prototype.concat(a,[].slice.call(arguments));
}
Praveen
  • 53,079
  • 32
  • 129
  • 156
YuC
  • 1,643
  • 3
  • 18
  • 22

1 Answers1

2

There is no difference other than implicitly or explicitly calling Array.prototype.concat.

It's unclear what you're trying to accomplish, but the function f can be simplified as follows.

var a = [];

var f = function() {
    a = a.concat( [].slice.call(arguments) );
}

You can find more information about Array.prototype.concat here. Additionally, this question has a good discussion of prototype functions.

Community
  • 1
  • 1
Austin Brunkhorst
  • 19,922
  • 6
  • 43
  • 57
  • thanks @Austin, i found the second way in a Chinese famous website named [Douban](http://douban.com), and i was wondering why they are using that way instead of an easier way. – YuC Dec 24 '13 at 03:02