On 23.08.2011 21:32, Allen Wirfs-Brock wrote:
The rough convention we were following for ES5 was that Object.* functions that 
were expected to be used in application layer code had short imperative names 
like keys, create, freeze, etc. Functions that were expected to be primarily 
used in meta layers of framework or other reflective purposes have long 
descriptive names.

I see, thanks for clarifications Allen, it makes sense. Though... the consistency also matters ;)

  The wordiness of the names is largely a function of the degrees of variation that might be 
consider.  For example, own vs. all properties or property names vs property descriptors.  
getOwnPropertyDescriptor/getOwnPropertyNames are the winners in that category.  
defineProperty/defineProperties don't need the "own" because properties are always 
defined on a specific object and don't need "descriptor" because there are no similar 
operations that don't use descriptors.



Yes.

And what about this method Object.getMethods(...), Object.getMethodNames(...). Do we need it? I think it can be useful (since methods can be non-enumerable, and Object.keys(...) won't help, and after Object.getOwnPropertyNames(...) you have to manually filter them when `typeof` is "function")

Dmitry.






On Aug 7, 2011, at 12:36 PM, Dmitry A. Soshnikov wrote:

Hi again,

I'm about to propose `Object.methods(obj)` meta-method (or 
`Object.getMethods(obj)`). Unfortunately naming convention is inconsistent 
(arrgh!) -- `Object.keys` (hello, Ruby and Prototype.js) vs. 
Object.getOwnPropertyNames (o_O hello Java), so the method name can be chosen 
later.

But the idea is to get the properties (or their names) which are methods on the 
object.

Proposed:

var foo = {
  bar: function () {},
  __proto__: {baz: function () {}}
};

- Object.getMethods(foo) ->  {bar: function () {}, baz: function () {}}

- Object.getOwnMethod(foo) ->  {bar: function () {}}

- Object.getMethodNames(foo) ->  ["bar", "baz"]

- Object.getOwnMethodNames(foo) ->  ["bar"]

Of course it can be easily implemented in JS itself just filtering the 
Object.getMySummerVacationWasLongOwnPropertyNames or Object.keys(...), but 
directly in the engine it will be more efficient.

Dmitry.
_______________________________________________
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

Reply via email to