主题
forOwn
js
_.forOwn(object, [iteratee=_.identity])
迭代对象自身可枚举字符串键属性,并为每个属性调用 iteratee
。迭代器使用三个参数调用:(value, key, object)。迭代函数可以通过显式返回 false
提前退出迭代。
¥Iterates over own enumerable string keyed properties of an object and invokes iteratee
for each property. The iteratee is invoked with three arguments: (value, key, object). Iteratee functions may exit iteration early by explicitly returning false
.
新增于
¥Since
0.3.0
参数
¥Arguments
object
(对象):要迭代的对象。¥
object
(Object): The object to iterate over.[iteratee=_.identity]
(函数):每次迭代调用的函数。¥
[iteratee=_.identity]
(Function): The function invoked per iteration.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
_.forOwn(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).