Skip to content

Instantly share code, notes, and snippets.

@eshrinivasan
Last active June 4, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eshrinivasan/f1755c80bb4d5107dc99ccc55c03ca81 to your computer and use it in GitHub Desktop.
Save eshrinivasan/f1755c80bb4d5107dc99ccc55c03ca81 to your computer and use it in GitHub Desktop.
console log wrapper, debug statement, utility
/*
Universal debug utility
*/
@eshrinivasan
Copy link
Author

eshrinivasan commented Jun 4, 2019

function debug() {
	//	Convert arguments into array to perform array operations
	var args = Array.prototype.slice.call(arguments);
	//	Takes the arguments array and checks if the last element is true and also removes last element
	isDebugOn = () => args.length > 1 && args.pop() === true;
	// 	Print on console if last element was true
	isDebugOn() ? console.log(args.join(',')) : ''; 
};

Usage:

debug(1, 2, true) //prints 1, 2
debug(1, 3) // Doesn't print output

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