kerdosa a écrit :
> It is opposite of what you described here.

No it's not.

> The properties added to prototype is shared by all the instance
> object, so it is static.

You misunderstood how the prototype mechanism works.  Properties defined
at the prototype level are not *shared* by all instances: they're
*copied* over to all instances.  Big, big difference.

Demonstration:

var MyClass = Class.create();

Object.extend(MyClass, { staticField: 42 });

Object.extend(MyClass.prototype, {
  instanceField1: 21,
  initialize(if2) { this.instanceField2 = if2; });
});

var mo1 = new MyClass(7);
// => mo1: Object instanceField1=21 instanceField2=7
var mo2 = new MyClass(6);
// => mo1: Object instanceField1=21 instanceField2=6
mo1.staticField
// => undefined property "staticField"
MyClass.staticField
// => 42
mo1.instanceField1 = 100
mo2.instanceField1
// => 21

See?
For tons of additional examples, just see *Prototype's source code*...

-- 
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to