JavaScript object walker

Ever wanted to recursively iterate through an object and its properties without writing all that boilerplate code? Now you can!

I've released some JavaScript code that will allow you to recursively walk a JavaScript object. You can find the code on github at https://github.com/matthewkastor/object-walk or install it through nodejs with npm install object-walk. It allows you to define both a descention function and an ascention function. The descention function is performed on every node and leaf from the top down. The ascention function is performed on every node from the bottom up. Nodes and leaves are an objects own enumerable properties. Nodes are the properties which are themselves objects. Leaves are the properties which are primitive values like strings and numbers. This makes it possible to do many operations on objects in a clean and concise manner and eliminates the possibilities of syntax errors. It will also save you from repetitive strain injuries caused by typing out the same boilerplate code over and over.

Enjoy!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.