简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM