One of the things I love about JavaScript is the fact that objects in JS are really just simple hashes of key/value pairs. What's nice about that is that the keys (properties, members, whatever you want to call them) are enumerable. So of course, we all know what that means, right? Right...you caniterate over JS objects. I mean, we all knew we could iterate over collections of objects, but the object itself? Yeah...its OK...I didn't realize it at first either, but its really nice to be able to do that. Knowing this opens up some nice possibilities, doesn't it?
Lets say, as an example, that you wanted or needed to write your own object extension/mixin functionality. Such a function would need to iterate over a source object in order to copy its members onto the target object, right? Lets take a look at how we might do something like that:...
Your new post is loading...