Prothon Prototypes vs Python Classes
Joe Mason
joe at notcharles.ca
Thu Apr 1 10:36:12 EST 2004
In article <gandreas-1F419E.08473601042004 at news.mpls.visi.com>, Glenn Andreas wrote:
>> There certainly is a standard syntax for making objects. I need to know
>> how to "duplicate an existing object". Is it "obj.dup()"?
>> "obj.clone()"? "duplicate obj"? Most probably, the language (or
>> standard library) defines one of these, and I expect most objects to be
>> duplicated in the same way.
>>
> It can be a bit more subtle than that in a prototype based system, since
> there are two things that are different, but have nearly identical
> results, but could both be considered "duplicate an object".
>
> In general, you don't want to _duplicate_ the object, but rather use
> that object as "prototype" for the new object.
>
> First, you can make a new object that has all the same
> slots/properties/attributes as the first object - let's just call that
> "clone" for now (and we'll assume single inheritence, via a slot called
> "__parent")
<snip example>
> and we'll make the second object that has first object as the __parent
> (and we'll pretend that the syntax is "new <some expression>"
<snip other example>
This is certainly how Self does it. Other prototype based languages
(such as Io) do not make this distinction. In Io, you use "clone" to
make a new object whose parent is the object it was cloned from, and
that's it.
Joe
More information about the Python-list
mailing list