Object.prototype.toSource = function () { var source = '{\n'; for ( var i in this ) { if ( this.hasOwnProperty( i ) ) { source += i + ': ' + this[i] + ',\n'; } } return source + '\n}'; };