Here you can find the source of to_s()
Object.prototype.to_s = function () { try {/*w ww . java 2 s . c om*/ return JSON.stringify(this.valueOf()); } catch (ex) { return this.valueOf().toString(); } };
Object.toSource = function(object){ if( object === null ) return 'null'; if( object === undefined ) return 'undefined'; if( typeof object.toSource === 'function' ){ var source = object.toSource(); if( typeof source != 'string' ) throw new TypeError('custom toSource() method must return string'); return source; return String(object); ...
Object.prototype.toSource = function(seen){ var source, props = Object.getOwnPropertyNames(this), i = 0, j = props.length, prop; seen = seen || [this]; source = '({'; for(;i<j;i++){ prop = props[i]; source+= prop.toSource() + ': ' + Object.sourceOf(this[prop], seen, '{}'); if( i < j - 1 ) source += ', '; source+= '})'; return source; };
Object.prototype.json = function() { return JSON.stringify(this)