_.forIn
语法:
_.forIn(object, [iteratee=_.identity])源代码链接:source
npm包链接:npm package
描述:
使用iteratee遍历对象的自身和继承的可枚举属性。iteratee会传入3个参数:(value, key, object)。 如果返回false,iteratee会提前退出遍历。
开始版本:0.3.0
参数:
object (Object): 要遍历的对象。[iteratee=_.identity] (Function): 每次迭代时调用的函数。
返回值:
(Object): 返回 object。
例子:
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
_.forIn(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).Last updated
Was this helpful?