On May 12, 10:13 am, Ryan Gahl <ryan.g...@gmail.com> wrote:
> > var j = new (Class.create({initialize: function(name){ this.x =
> > 5; }}));
> > j.x; // 5
>
> Sure, but for some reason I highly doubt that's what he was going for.
> That's a non-reusable class definition, after all. He'd be much better off
> just removing his "new" and creating the instance after the class
> declaration, as he can then create other instances of the class (which is
> most likely what he wants).
>
> Was trying not to confuse the guy with an advanced discussion like this.
> "Just remove the 'new' keyword" probably served the purpose of helping him
> get past his issue just fine, and represents a closer to real life
> situation. No one creates instances like that, kangax, and you know it :)

Sorry if I was overly pedantic :)
Yes, Ryan, that "pattern" is not something I would recommend; it was
just a peculiar case of an operator precedence that I wanted to
clarify for anyone interested.

And again, technically speaking, I can see how anonymous constructor
can be used for creating an object with non-delete'able members. I've
seen people do such thing, but I've never done it myself and don't see
much reason for doing so (these non-delete'able properties are still
mutable, after all).

function F(){};
F.prototype.x = 5;
var o = new F;

o.x; // 5
delete o.x; // true
o.x; // 5

// whereas:

var o = { x: 5 }

o.x; // 5
delete o.x; // true
o.x; // undefined

Just thought I should mention it : )

[...]

--
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to