× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS
Jon Tewksbury
Feb 12, 2015
<p>Building off of your existing code is a great way to keep things DRY (don't repeat yourself).</p> <p>In a recent session, I had my mentee rewrite underscore's/lo-dash's each method. This was a great exercise as it requires the use of callback funcitons, a cornerstone of javascript programming. It also required him to learn how arguments are passed from one function to the next.</p> <p>Once we had completed that, I had him rewrite the function map, but it had to make use of the function each that he had just written. This is a very important part of writing clean and maintainable code, and keeping your code concise. By making your functions as modular as possible, it becomes easier to reuse them later on, which helps you write less code, and since each funciton is defined once and used many times later on, if you discover a problem with your function, you only need to fix it in one spot.</p> <p>If you want a good exercise in callbacks and code reuse, write the each function from scratch, then use it to write map from scratch.</p>
comments powered by Disqus