_.forIn(object, [iteratee=_.identity])
使用 iteratee
遍歷對象的自身和繼承的可枚舉屬性。
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' (無法保證遍歷的順序)。
_.forOwn(object, [iteratee=_.identity])
使用 iteratee
遍歷自身的可枚舉屬性。
function Foo() { this.a = 1; this.b = 2; } Foo.prototype.c = 3; _.forOwn(new Foo, function(value, key) { console.log(key); }); // => 輸出 'a' 然后 'b' (無法保證遍歷的順序)。