在原型对象上创建的方法是共享的
Array.prototype.norepeat = function(){
//this指向要去重的数组
return [...new Set(this)];
}
var arr = [1,2,5,1,5,15,1,3];
var res = arr.norepeat();
console.log(res) //[1, 2, 5, 15, 3]
在原型对象上创建的方法是共享的
Array.prototype.norepeat = function(){
//this指向要去重的数组
return [...new Set(this)];
}
var arr = [1,2,5,1,5,15,1,3];
var res = arr.norepeat();
console.log(res) //[1, 2, 5, 15, 3]
转载于:https://www.cnblogs.com/ccyq/p/11294582.html