Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jQuery.print: keep track of seen objects to prevent infinite recursio…

…n; truncate strings inside objcts
  • Loading branch information...
commit 4e47ead54edccc56e241b921f6ac4f112786c65d 1 parent 49a5dda
@tmm1 tmm1 authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/jquery.print.js
View
14 lib/jquery.print.js
@@ -3,8 +3,8 @@
// helper functions
function print_array(obj, opts){
- var max = obj.length > opts.maxArray ? opts.maxArray : obj.length
opts.maxString = 25
+ var max = obj.length > opts.maxArray ? opts.maxArray : obj.length
var result = [];
for (var i = 0; i < max; i++) {
@@ -25,10 +25,16 @@
">"
}
- function print_object(obj){
+ function print_object(obj, opts){
+ opts.maxString = 25
+ if (!opts.seen) opts.seen = []
+
var result = []
for (var k in obj) {
- result.push(k + ": " + $.print(obj[k]))
+ if (opts.seen.indexOf(obj[k]) == -1) {
+ opts.seen.push(obj[k])
+ result.push(k + ": " + $.print(obj[k], opts))
+ }
}
if (result.length == 0) return "{}"
@@ -107,7 +113,7 @@
return print_jquery(obj)
else if (obj instanceof Object)
- return print_object(obj)
+ return print_object(obj, opts)
else
return obj.toString().replace(/\n\s*/g, '')

0 comments on commit 4e47ead

Please sign in to comment.
Something went wrong with that request. Please try again.