Please some small improvements

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Mar 20 14:53:15 PDT 2012


On Mar 20, 2012, at 2:10 PM, John J Barton wrote:

> I've been reading a lot of nicely written JS in the Traceur compiler.
> They use a very conservative Java-like approach with Constructor
> functions and literal prototype property declarations. Sadly they must
> include workarounds for Object.create:
> 
> http://code.google.com/p/traceur-compiler/source/browse/src/traceur.js#80
> 
> WebInspector has a bit more rough and ready JS style, eg
> 
> WebInspector.View.prototype.__proto__ = WebInspector.Object.prototype;
> 
> Here's the irony: we can change the WebInspector code to use
> Object.create() specifically because they do not use object literal
> declarations for functions (and thus one line will make improvement).
> 
> Since es-discuss seems quite keen on object literals, a couple of
> small improvements would help code move in your direction:
> 
>  A version of Object.create() that takes an object RHS.

Because you explicitly mention object literals, I assume your intent would be to use an object literal as the second argument to such functions.  For example such as is done in [1] that starts out as:

  LoadCodeUnit.prototype = traceur.createObject(CodeUnit.prototype, {
    allowLoad: true,

    get moduleSymbol() {
      return this.project.getModuleForUrl(this.url)
    },
    ...

In ES.next, based upon current proposals, the equivalent can be directly expressed  using <| without any additional function calls:

  LoadCodeUnit.prototype = CodeUnit.prototype <| {
    allowLoad: true,

    get moduleSymbol() {
      return this.project.getModuleForUrl(this.url)
    },
    ...
In other words, <| is the operator forms of the function you are requesting for the object literal use case.  Note that the operator form is likely to be significantly more efficient as it only needs to do one object allocation.  The function form has to allocated the object literal that is passed as the argument to createObject and and then allocate a second object within createObject (and copy poperties between the two).



[1] http://code.google.com/codesearch#IW7-zY8plzo/trunk/src/runtime/modules.js&q=createObject%20package:http://traceur-compiler%5C.googlecode%5C.com&l=195 


> 
>  Object.merge() that merges the own non-function properties as own
> properties, the non-built-in-functions as prototype properties. (a
> compromise of the two common versions of extend, own and 'in'
> versions).

and what about own built-in function properties? 

We have talked about providing some form of "extend".  Do you have specific usage scenarios that support the specific set you rules you just listed. 

Allen






> 
> jjb
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120320/b3402f56/attachment.html>


More information about the es-discuss mailing list