YuC
YuC

Reputation: 1847

what's the difference between below js codes?

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));
}

Upvotes: 0

Views: 52

Answers (1)

Austin Brunkhorst
Austin Brunkhorst

Reputation: 21130

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.

Upvotes: 2

Related Questions