Object.methods

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Aug 23 10:32:31 PDT 2011


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

Allen






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
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 



More information about the es-discuss mailing list