Tap for quick debugging

This little beastie here is tap. A really useful function for quick-debugging chains of function calls, anonymous functions and, actually, whatever you just want to print.

Why would you use instead of good old console.log? Let me show you an example:

Now, suppose you’re getting nothing from this chain (possibly an error). Where is it failing? Maybe bank_info isn’t returning anything, so we’ll tap it:

Depending on our particular implementation, it might print something or not. I’ll assume the information that we got from our tapping was correct and therefore, bank_info isn’t causing anything.

We must then move on to the next chain, filter.

Are we receiving any c’s (clients actually)? If so, then bank_totals_by_client works alright. Maybe it’s the condition within the filter?

Ah! Sweet, we see nothing but false printed, so there’s no client with >25000, that’s why the function was returning nothing.

(Bonus) A more advanced tap.

Now we’re talking about a more advanced beast, what if we wanted to perform a certain operation prior to tapping? i.e, we want to access a certain object property, perform a logical operation, etc. with our tapped object? Then we call old good tap with an extra argument, a function to be applied at the moment of tapping.

If you want to improve Tap let your answer in comment section below.

Arif Khoja
Arif Khoja is a Developer. He is a Javascript Enthusiatic who loves logical programming and has first hand experience in building a cutting edge internet product using Angular. He is also an open source freak and keen about learning and sharing. He writes Javascript both frontend and backend. He loves learning and sharing tech all the time. He also has a hands on experience in SEO and writes articles about latest emerging technologies.
Arif Khoja on FacebookArif Khoja on GoogleArif Khoja on InstagramArif Khoja on LinkedinArif Khoja on Twitter

Leave a Reply

%d bloggers like this: