The example chosen was poor. It is true that the example could be trivially implemented right now.
Object.create is most useful when either A) using inheritance without functions, or B) when changing the enumerable, writable, and configurable properties. In that case the extra code would be needed. The example didn't demonstrate either of those cases, so of course it looks like meaningless boilerplate. As was said, "You could even chose to make those non-enumerable or lock them with values." That was the point, I believe. It allows you not only to remove the "new" at the front of constructors, but also allows you to configure property flags. I already provided an example that shows how to do inheritance without needing constructor functions at all, which I believe was the primary intent of Object.create. On Aug 14, 1:47 am, Andrea Giammarchi <andrea.giammar...@gmail.com> wrote: > We are not under a unified VM (syntax not usable) and I cannot spot a single > benefit using two calls rather than one plus implicit init method. > > // right now > function Man(name){ > // here Man prototype has been already inherited > // and it is usable from "this" > // a constructor is an implicit init method > // let's define the name > this.name = name; > > }; > > var me = new Man("Andrea"); > > // boring future coolness > function Man(name){ > // no instance here, this is the global object > // so we have to call another method from global Object > // requiring scope resolution (Object) property access (create) > // and finally function call plus property access (Man.prototype) > // one up to tow objects creation plus a return > return Object.create(Man.prototype, { > name:{ > value:name > } > }); > > }; > > So, size wise speaking, we are simply incrementing without a valid reason > our scripts. > Performance speaking, we are simply incrementing execution time for each > instance creation. > > WOW, this ES5 will bring a lot of features, isn't it? > > wanna obtain the same behavior? EASY > > function Man(name){ > if(!(this instanceof Man)) > return new Man(name); > this.name = name; > > }; > > var me = Man("Andrea"); > > Still less code, function duality used if necessary, and total cross browser > compatibility. > > Regards --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---