Skip to content

Instantly share code, notes, and snippets.

@lulezi
Created August 28, 2014 10:59
Show Gist options
  • Save lulezi/e50f0fabce9aaa827360 to your computer and use it in GitHub Desktop.
Save lulezi/e50f0fabce9aaa827360 to your computer and use it in GitHub Desktop.
Quick Fix for ember.js error "Cannot convert object to primitive value"
function inspect(obj) {
var type = typeOf(obj);
if (type === 'array') {
return '[' + obj + ']';
}
if (type !== 'object') {
return obj + '';
}
var v;
var ret = [];
for(var key in obj) {
if (obj.hasOwnProperty(key)) {
v = obj[key];
if (v === 'toString') { continue; } // ignore useless items
if (typeOf(v) === 'function') { v = "function() { ... }"; }
if (typeOf(v) === 'object') { v = '[object]'; }
ret.push(key + ": " + v);
}
}
return "{" + ret.join(", ") + "}";
}
@lulezi
Copy link
Author

lulezi commented Aug 28, 2014

Add line #17 to fix ember.js error "Cannot convert object to primitive value". Use at your own risk!

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