Skip to content

Commit

Permalink
jQuery.print({a:1}) => "{ a: 1 }"
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed May 5, 2008
1 parent f586f5b commit 49c052a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/jquery.print.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
if (obj.length > max)
result.push('... ' + (obj.length - max) + ' more')

return "[" + result.join(", ") + "]";
if (result.length == 0) return "[]"
return "[ " + result.join(", ") + " ]"

} else if (obj instanceof HTMLElement) {
return "<" + obj.tagName.toLowerCase() +
(obj.className != "" ? " class='" + obj.className + "'" : "") +
(obj.id != "" ? " id='" + obj.id + "'" : "") +
">";
">"

} else if (obj instanceof jQuery) {
var result = []
Expand All @@ -39,7 +40,8 @@
for (var k in obj) {
result.push(k + ": " + $.print(obj[k]))
}
return "{" + result.join(", ") + "}"
if (result.length == 0) return "{}"
return "{ " + result.join(", ") + " }"

// XXX "abc" instanceof String # => false
} else if (obj instanceof String) {
Expand Down

0 comments on commit 49c052a

Please sign in to comment.