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
<[email protected] <mailto:[email protected]>> 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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss