Skip to content

Instantly share code, notes, and snippets.

@gabehollombe
Created March 8, 2012 12:56
Show Gist options
  • Save gabehollombe/2000882 to your computer and use it in GitHub Desktop.
Save gabehollombe/2000882 to your computer and use it in GitHub Desktop.
Helpful CoffeeScript console debugging function
d = (s) -> o = {}; o[k] = eval(k) for k in s.split(' '); console.log JSON.stringify(o, null, ' ')
# Or, the compiled JavaScript:
d = function(s) {
var k, o, _i, _len, _ref;
o = {};
_ref = s.split(' ');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
k = _ref[_i];
o[k] = eval(k);
}
return console.log(JSON.stringify(o, null, ' '));
};
# Stop writing things like:
# console.log "some_var: #{some_var} - some_other_var: #{some_other_var}"
# Instead, just pass in a string of the vars you're interested in,
# and get back the results in an easy to read format.
#
# Usage: d 'some_var some_other_var'
# IN: A string of var names.
# OUT: A log entry in your console of an object
# where the keys are the var names and the values are the vars' values.
#
# For example...
#
# If we have these vars:
# num = 1
# str = 'some string'
# obj = {name: 'Gabe', age: 31, foods: ['Sushi', 'Pizza']}
#
# And we call: d 'num str obj'
#
# The console log writes:
#{
# "num": 1,
# "str": "some string",
# "obj": {
# "name": "Gabe",
# "age": 31,
# "foods": [
# "Sushi",
# "Pizza"
# ]
# }
#}
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment