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
  • 55,303
  • 33
  • 133
  • 164
YuC
  • 1,787
  • 3
  • 19
  • 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
  • 20,704
  • 6
  • 47
  • 61
  • 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