-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for prototype #14
Comments
It seems reasonable to have something like Presumably, it would apply to any object that wasn't otherwise handled, that had a [[Prototype]] that was not For null objects, this is easy (and not what you asked about, but worth handling anyways). However, what about cross-realm objects? Say something whose inheritance chain is "object → |
Sorry for the late reply!
I prefer the syntax
Sounds reasonable to me.
You lost me here. I don't even think we have to manually inspect the prototype chain. I just came upon the MDN documentation for if (!isDate(obj) && !isRegExp(obj)) {
var constructor = obj.constructor;
var prefix = constructor && constructor !== Object
? constructor.name + ' '
: '';
var xs = arrObjKeys(obj, inspect);
var body = xs.length > 0
? '{ ' + xs.join(', ') + ' }'
: '{}';
return prefix + body;
} |
First, values from another realm (like an iframe) won't have the same Separately, the |
Thanks for the clarification! Let me think that over. |
I believe that identifying another realm's But I'm seeing a second problem here: How do we get a string representation of an object's prototype? The only "official" way I'm aware of is |
Good code is robust against insane developers too; we won't do a string comparison.
I'm not aware of any possible way to get another realm's |
What about the second problem I mentioned? |
I would possibly be content to use the constructor’s name after any possibility of it being a builtin is removed, and after checking Object.prototype.toString.call (which isn’t robust for builtins in ES6, but works fine for non-builtins) |
I've created a pull request: #15. I'm sure there are some corner cases I haven't thought of, but I think it's a good start. I'd welcome your feedback! |
Thank you for your comments! I've fixed the wrong function call you spotted and answered your questions. |
@ljharb: Is there anything more I can do? I'd love to see this PR accepted. |
I've indicated why I think the majority of this idea is just not tenable in practice; I'll give the PR another review just in case. |
This package is great for creating debug output! I just compared it to a number of similar packages (
eyes
,jsenc
,js-stringify
,javascript-stringify
, andstringify-object
), and the output ofobject-inspect
was by far the most helpful!There is only one case where I'd love a bit more information, and that is when working with prototypes / ES2015 classes. Consider this code:
The output is
{ a: 1, b: 2, c: 42 }
, so the information that this is an instance of classFoo
gets lost.I noticed that for certain built-in types like
Map
, you prefix the output with the class name. It would help me a lot if you could do the same for other prototypes. In my case, that would make the outputFoo { a: 1, b: 2, c: 42 }
.The text was updated successfully, but these errors were encountered: