To create an object in ES3, yes. (ES3; ECMAScript 3; Current JavaScript) ES5 adds a new method which follow the proper prototypal method (ES5; ECMAScript 5; The next version, ES4 was discarded)
Object.create(proto, {...}); The first argument is a prototype to give it: Object.create(Foo.prototype); is roughly the same as, in mozilla js: ({ __proto__: Foo.prototpe }) in normal js function F() {} F.prototype = Foo.prototype; new F; Just so you know the {...} is a object listing keys to add. Each key has an object with data like value: (the value), or get: (a getter) and/or set: (a setter), as well as the attributes enumerable (part of for-in loops), writable (you can set it), and configurable (it can be removed using `delete o.prop`) There's a nice new idiom which involves using Object.create inside a function, using that function's prototype as the proto, setting properties, and returning that object. Essentially it does the same as using `new Fn` except it gives you more control, and works whether you use new or not. There's also an interesting new strawman that was recently brought into the harmony group, makes this possible: function Foo() { return { [parent: Foo.prototype], foo: "I'm a value", const _bar: "You can't set or delete me after this", }; } ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name] Samer Ziadeh wrote: > Isn't the 'new' a needed keyword? > > On Thu, Aug 13, 2009 at 08:04, Andrea Giammarchi > <andrea.giammar...@gmail.com <mailto:andrea.giammar...@gmail.com>> wrote: > > Python rules, and I mainly agree, except the day "new" will not be > necessary anymore we'll loose constructor duality, as functions, > and implicit injected "init" methods. > > Regards > > > On Tue, Aug 11, 2009 at 3:46 AM, Daniel Friesen > <nadir.seen.f...@gmail.com <mailto:nadir.seen.f...@gmail.com>> wrote: > > > The requirement of "new" to create new js objects is an > unnecessary > piece of the language, in fact the need to use it disappears > in ES5 as > it's no longer the only way to create new objects with a set > prototype. > There's nothing strange about having a $ function and creating > an object > from it, in fact it's closer to real prototype-based > programming than > the `new Class` you see inside of JavaScript. > > ~Daniel Friesen (Dantman, Nadir-Seen-Fire) > [http://daniel.friesen.name] > > > > > > > -- > Samer Ziadeh > www.samerziadeh.com <http://www.samerziadeh.com> > > > "Let It Be" > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---