From 47dfdd98a2c50fa31de965d99ce33a0acbe2511e Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 20 Oct 2013 12:27:07 -0400 Subject: [PATCH] added _.forIn definition --- lodash/lodash-tests.ts | 12 ++++++++++++ lodash/lodash.d.ts | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5790b68628..e8c44b6f16 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -554,6 +554,18 @@ result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) return num % 2 == 1; }); +function Dog(name) { + this.name = name; +} + +Dog.prototype.bark = function() { + console.log('Woof, woof!'); +}; + +_.forIn(new Dog('Dagny'), function(value, key) { + console.log(key); +}); + var mergeNames = { 'stooges': [ { 'name': 'moe' }, diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 7d6eb3b8c3..6c4d45e2ae 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2263,6 +2263,21 @@ declare module _ { object: any, whereValue: Dictionary): string; + /** + * Iterates over own and inherited enumerable properties of an object, executing the callback for + * each property. The callback is bound to thisArg and invoked with three arguments; (value, key, + * object). Callbacks may exit iteration early by explicitly returning false. + * @param object The object to iterate over. + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + * @return object + **/ + export function forIn( + object: Dictionary, + callback?: ObjectIterator, + thisArg?: any): Dictionary; + + /** * Recursively merges own enumerable properties of the source object(s), that don't resolve * to undefined into the destination object. Subsequent sources will overwrite property