Object.prototype.inspect ?

Brendan Eich brendan at mozilla.com
Thu Mar 12 15:49:01 PDT 2009

On Mar 12, 2009, at 1:33 PM, Brendan Eich wrote:

> On Mar 12, 2009, at 3:54 AM, Tobie Langel wrote:
>> On Mar 11, 2009, at 21:32 , Brendan Eich wrote:
>>> Want to help?
>> Sure. How?
> The discussion here should focus on use-cases, which will help us  
> write down requirements and anti-requirements. If we only care about  
> diagnostic inspection, not round-tripping equivalent object graphs  
> (the two are not always cleanly separable), we should say what does  
> round trip, what does not (native data including method references,  
> e.g.).

So [0,1,[2,3]] => "[0, 1, [2, 3]]" is good for both hi-fi serialize/ 
deserialize value recovery, and (I claim) for human inspection. But a  
really long and/or deep array structure would be unreadable, so  
ellipses might be appropriate for the human in the loop. IMHO we  
should borrow from Python (again) on pragmatic stuff like eliding  
overlong repr strings.

Native functions converting to strings as in

js> Array.prototype.toString
function toString() {
     [native code]

is an ancient convention that's not standardized. It's unfortunate in  
that it throws 13 characters plus braces and spaces at telling the  
user "no source here", but at least it can't compile into a valid  
program to be mis-executed. With anything like a standardized  
toSource, we can do better. Again the pragmatic detailing is worth  
getting right. Start by citing precedent in Python and other  
languages, maybe? I'd find that helpful.


More information about the Es-discuss mailing list