Array.prototype.join.call([1,2,3,4])
"1,2,3,4"
Array.prototype.join.bind([1,2,3,4])()
"1,2,3,4"
Array.prototype.join.apply([1,2,3,4])
"1,2,3,4"
[1,2,3,4].join()
"1,2,3,4"
[1,2,3,4].reduce((acc, key,index) => {
if(index!=0){
acc += ',' + key;
}else{
acc = key
}
return acc;
}, '')
[1,2,3,4].toString()
VM21:7 Uncaught TypeError: "1,2,3,4"[(1 , 2 , 3 , 4)].join is not a function
at <anonymous>:7:11
(anonymous) @ VM21:7
[1,2,3,4].toString()
"1,2,3,4"
Array.prototype.getString = function(){
var array = this;
return this.join(',');
}
ƒ (){
var array = this;
return this.join(',');
}
[1,2,3,4].getString()
"1,2,3,4"
Array.prototype.getString.apply([1,2,3,4])
"1,2,3,4"
网友评论