Fre*_*ind 5 javascript function
我为数组定义了两个函数:
Array.prototype.remove = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
this.removeAt(i);
}
}
};
Array.prototype.removeAll = function(array2) {
array2.forEach(function(item) {
this.remove(item); // remove not found!!
});
}
Run Code Online (Sandbox Code Playgroud)
但在removeAll功能方面,它报道function remove is not found.我修复它像这样:
Array.prototype.removeAll = function(array2) {
var outer = this;
array2.forEach(function(item) {
outer.remove(item);
});
}
Run Code Online (Sandbox Code Playgroud)
但它很难看.有没有更好的办法?
| 归档时间: |
|
| 查看次数: |
1128 次 |
| 最近记录: |