JS小技巧
1,让一个object支持数组遍历函数的写法:
['filter','forEach','every','map','some'].forEach(function(name){
Collection.prototype[name]=function(){
returnArray.prototype[name].apply(this._items, arguments);
}
});
2,遍历对象时为什么要加hasOwnPropertyOf()?为了判断false之类的属性值。
1,让一个object支持数组遍历函数的写法:
['filter','forEach','every','map','some'].forEach(function(name){
Collection.prototype[name]=function(){
returnArray.prototype[name].apply(this._items, arguments);
}
});
2,遍历对象时为什么要加hasOwnPropertyOf()?为了判断false之类的属性值。