Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Can somebody give me an example how I can call this forEachIn function Date: Sun, 11 Jan 2015 17:43:32 +0100 Organization: PointedEars Software (PES) Lines: 39 Message-ID: <21533753.SDDzv5OC2z@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1420994632 15514 eJwFwQkRwDAMAzBKrWfngbPLwx9CJX12rZwmo1bbyR0XmKcQMc0rTnuibv4OtwxQhZ2ZjvMAEEwQww== (11 Jan 2015 16:43:52 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 11 Jan 2015 16:43:52 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVisdnnCD2H6F3biHRifCAr68kyRadRlrNrimAM9VLrSeq9GPJmzdODb9y8t362rhP8QNK3BV3 Cancel-Lock: sha1:2+qXb74jSvbZgwzGAoJexvovaHw= X-NNTP-Posting-Host: eJwFwYERAEEEBLCWeLuMcnD0X8InNFefgNPB48UJiLbLnV3NEitKh71ZcOY69auS5zwD8gcqMRGJ Xref: csiph.com comp.lang.javascript:26548 Martin Honnen wrote: > Tony Johansson wrote: >> function forEachIn(object, action) >> { >> for(var property in object) >> { >> if (object.hasOwnProperty(property)) >> { >> action(property, object[property]); >> } >> } >> } > > For instance, > > var obj = { prop1: 'foo', prop2: 42 }; > > forEachIn(obj, function(propName, propValue) { > console.log(propName + ' has value "' + propValue + '"'); > }); > > will output > > prop1 has value "foo" > prop2 has value "42" The for-in iteration order is not defined, so the lines above could be reversed. > --- news://freenews.netfront.net/ - complaints: news@netfront.net --- I strongly suggest not to use that service, it is a major source of trolls. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.