object wont iterable through Object.each #2408

Closed
newbie78 opened this Issue Aug 15, 2012 · 2 comments

Projects

None yet

2 participants

@newbie78

please help!
http://jsfiddle.net/qYFKp/
is this bug or feature?

Owner

Object.forEach and Object.each only iterate own properties (see: hasOwnProperty). By creating the logic object in the Class definition, upon instantiation you get an instance of a new object using your logic object as prototype, rather than the logic object itself. The reason for this is inheritance: 1. Changing the object's properties in an instance won't have effect on the actual class definition (it would if the object itself was used in the instance (either assigned or through the Class' prototype)). 2. Changing the object in the class definition will properly reflect in instances of that class (it wouldn't if the object was cloned in the instance).

If you want an object with its own properties, and therefore be able to use Object.each to iterate its values, you'd have to create it in the instance itself (like in the initialize method). Another option is to use a way of looping that does not care about own properties (for...in?). In general the first option would be appropriate.

@timwienk timwienk closed this Aug 16, 2012

im create logc object in class constructor and it's working
thanks for the response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment