Re: Would some like Object.inspect(myObj) be useful?
2012/6/14 Allen Wirfs-Brock al...@wirfs-brock.com On Jun 14, 2012, at 10:52 AM, Brendan Eich wrote: ... Thanks. Any reason this wasn't included in ES5 that you recall? Minimalism. Object.* wasn't intended to be a comprehensive reflection library, just a set of essential primitives that could be used tin building such. I think that was a good choice. There are many utility functions one may want to build on top of ES5's set of primitives. For example, traits.js was my attempt at providing a minimal number of utilities to treat property descriptor maps as composable traits. (The above inspect function is exactly traits.js's Object.getOwnProperties which lifts an object literal into a property descriptor map, cf. http://soft.vub.ac.be/~tvcutsem/traitsjs/api.html) Cheers, Tom ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Would some like Object.inspect(myObj) be useful?
Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
On 14 June 2012 10:42, Hemanth H.M hemanth...@gmail.com wrote: Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. Is there a proposal or strawman you're referring to? I'm not immediately seeing it, but I'm still new here. PrototypeJS has an Object.inspecthttp://api.prototypejs.org/language/Object/inspect/function, but I don't see a strawman suggesting it join the specification. -- T.J. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
No there is no proposal of that I'm aware of in Strawman, just asking the group if it's useful? On Thu, Jun 14, 2012 at 3:23 PM, T.J. Crowder t...@crowdersoftware.comwrote: On 14 June 2012 10:42, Hemanth H.M hemanth...@gmail.com wrote: Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. Is there a proposal or strawman you're referring to? I'm not immediately seeing it, but I'm still new here. PrototypeJS has an Object.inspecthttp://api.prototypejs.org/language/Object/inspect/function, but I don't see a strawman suggesting it join the specification. -- T.J. -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
Le 14/06/2012 11:42, Hemanth H.M a écrit : Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. In ES5, there are Object.getOwnPropertyNames as well as Object.getOwnPropertyDescriptor. These are the lowest-level constructs you need to do any introspection, I think. David ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
On 14 June 2012 11:07, Hemanth H.M hemanth...@gmail.com wrote: No there is no proposal of that I'm aware of in Strawman, just asking the group if it's useful? I can't speak for the group, but I think you'd need to explain it a lot more. :-) What would it return? How does it relate to the existing reflect_api harmony proposalhttp://wiki.ecmascript.org/doku.php?id=harmony:reflect_api? How does it differ from something built using Object.keys or for..in? Does it include non-enumerable properties? When you say attributes, do you mean properties or something else? Not harshing, just trying to understand what you're raising. (Side note: The convention on the list seems to be quote-first and comment below the quote [as above], rather than the other way around [which is gmail's default].) -- T.J. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
On Thu, Jun 14, 2012 at 5:42 AM, Hemanth H.M hemanth...@gmail.com wrote: Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. What would this function return? There's already an Object.keyshttps://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keyssfunction - does that do what you wanted? That's in ES5. - Russ -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
The inspect module provides functions for introspecting on live objects and their source code. On Thu, Jun 14, 2012 at 6:21 PM, Russell Leggett russell.legg...@gmail.comwrote: On Thu, Jun 14, 2012 at 5:42 AM, Hemanth H.M hemanth...@gmail.com wrote: Was just wondering if something like *Object.inspect(myObj) *would give all the attributes of that particular object. What would this function return? There's already an Object.keyshttps://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keyssfunction - does that do what you wanted? That's in ES5. - Russ -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
On Jun 14, 2012, at 9:49 AM, Hemanth H.M wrote: The inspect module provides functions for introspecting on live objects and their source code. As do many of the ES5 methods in Object.*. It's not clear what you mean by source code in this context. If you want to have discussion about an idea like this you have to provide a much more complete description of what you have in mind. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
var info = { name: Hemanth, url: http://h3manth.com/;, location : Earth, get : function() {} }; Object.keys(info) [name, url, location, get] Now, it's not clear about the 'type' of the keys; name is a String, where as get is a function. Compared to something like inspect module in python that give o/p like : ('__delslice__', method-wrapper '__delslice__' of list object at 0x1005252d8) On Thu, Jun 14, 2012 at 10:41 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: On Jun 14, 2012, at 9:49 AM, Hemanth H.M wrote: The inspect module provides functions for introspecting on live objects and their source code. As do many of the ES5 methods in Object.*. It's not clear what you mean by source code in this context. If you want to have discussion about an idea like this you have to provide a much more complete description of what you have in mind. Allen -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
Hemanth H.M wrote: var info = { name: Hemanth, url: http://h3manth.com/;, location : Earth, get : function() {} }; Object.keys(info) [name, url, location, get] Now, it's not clear about the 'type' of the keys; name is a String, where as get is a function. Compared to something like inspect module in python that give o/p like : ('__delslice__', method-wrapper '__delslice__' of list object at 0x1005252d8) Python's repr convention is missed in JS, but instead of trying to force everything into a standard string representation, how about just building on ES5 (already mailed to you, sharing with list here): js o = {p:1, q:2, get r(){return 3}} ({p:1, q:2, get r () {return 3;}}) js function inspect(o) { var a = []; Object.getOwnPropertyNames(o).forEach(function (k) { a.push(Object.getOwnPropertyDescriptor(o, k)); }); return a; } js d = inspect(o) [{configurable:true, enumerable:true, value:1, writable:true}, {configurable:true, enumerable:true, value:2, writable:true}, {configurable:true, enumerable:true, get:(function () {return 3;}), set:(void 0)}] ES5 has plural Object.defineProperties for defining more than one property on an object, and of course Object.create that defines all the properties on a new object from a descriptor-map. But it doesn't have anything like this inspect. We could add such an Object.getPropertyDescriptors API, for sure. /be On Thu, Jun 14, 2012 at 10:41 PM, Allen Wirfs-Brock al...@wirfs-brock.com mailto:al...@wirfs-brock.com wrote: On Jun 14, 2012, at 9:49 AM, Hemanth H.M wrote: The inspect module provides functions for introspecting on live objects and their source code. As do many of the ES5 methods in Object.*. It's not clear what you mean by source code in this context. If you want to have discussion about an idea like this you have to provide a much more complete description of what you have in mind. Allen -- /'I am what I am because of who we all are'/ h3manth.com http://www.h3manth.com /-- Hemanth HM/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
WOW! Thanks a ton for the clarification. On Thu, Jun 14, 2012 at 10:52 PM, Brendan Eich bren...@mozilla.com wrote: ES5 has plural Object.defineProperties for defining more than one property on an object, and of course Object.create that defines all the properties on a new object from a descriptor-map. But it doesn't have anything like this inspect. We could add such an Object.getPropertyDescriptors API, for sure. -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
Brendan Eich wrote: ES5 has plural Object.defineProperties for defining more than one property on an object, and of course Object.create that defines all the properties on a new object from a descriptor-map. But it doesn't have anything like this inspect. We could add such an Object.getPropertyDescriptors API, for sure. Object.getOwnPropertyDescriptors, I should have written. Own, *sigh*. /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
Allen Wirfs-Brock wrote: On Jun 14, 2012, at 10:22 AM, Brendan Eich wrote: Hemanth H.M wrote: var info = { name: Hemanth, url: http://h3manth.com/;, location : Earth, get : function() {} }; Object.keys(info) [name, url, location, get] Now, it's not clear about the 'type' of the keys; name is a String, where as get is a function. Compared to something like inspect module in python that give o/p like : ('__delslice__',method-wrapper '__delslice__' of list object at 0x1005252d8) Python's repr convention is missed in JS, but instead of trying to force everything into a standard string representation, how about just building on ES5 (already mailed to you, sharing with list here): js o = {p:1, q:2, get r(){return 3}} ({p:1, q:2, get r () {return 3;}}) js function inspect(o) { var a = []; Object.getOwnPropertyNames(o).forEach(function (k) { a.push(Object.getOwnPropertyDescriptor(o, k)); You probably want to make the above line: a.[k] = Object.getOwnPropertyDescriptor(o,k} Confusing .[ typo there :-P. This should give you a descriptor that can be passed back into Object.defineProperties Also initialize a to { }. Let me redo the REPL session: js o = {p:1, q:2, get r(){return 3}} ({p:1, q:2, get r () {return 3;}}) js function inspect(o) { var r = {}; Object.getOwnPropertyNames(o).forEach(function (k) { r[k] = Object.getOwnPropertyDescriptor(o, k); }); return r; } js d = inspect(o) ({p:{configurable:true, enumerable:true, value:1, writable:true}, q:{configurable:true, enumerable:true, value:2, writable:true}, r:{configurable:true, enumerable:true, get:(function () {return 3;}), set:(void 0)}}) Thanks. Any reason this wasn't included in ES5 that you recall? /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Would some like Object.inspect(myObj) be useful?
On Jun 14, 2012, at 10:52 AM, Brendan Eich wrote: ... Thanks. Any reason this wasn't included in ES5 that you recall? Minimalism. Object.* wasn't intended to be a comprehensive reflection library, just a set of essential primitives that could be used tin building such. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss