Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Inheritance changes
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sam Stephenson  
View profile  
 More options Oct 11 2007, 1:50 pm
From: Sam Stephenson <s...@37signals.com>
Date: Thu, 11 Oct 2007 12:50:08 -0500
Local: Thurs, Oct 11 2007 1:50 pm
Subject: Re: [Prototype-core] Inheritance changes

> I just saw that there were some more changes with the inheritance  
> code.
> I'm wondering how stable is the code.  Meaning, if I start working  
> on a
> project and use the current inheritance code right now, what  
> probability
> is there that I'll need to rename functions (addMethods) or change
> function calls (such as changing the $super construct)?

The changes to the class API introduced in [7833] (http://dev.rubyonrails.org/changeset/7833
) are a result of feedback we've gotten from 1.6.0_rc0, and of  
numerous lengthy internal debates.  Our goal was to improve the  
clarity of the API as well as pave the way for features that may make  
their way into future versions of Prototype.

To that end, we've eliminated the Class.extend and Class.mixin  
methods, improved the Class.create syntax, and changed the way you add  
methods to existing classes.  The API is still backwards-compatible  
with all pre-1.6 versions of Prototype.  We haven't changed the way  
inheritance works, and you still access superclass methods using the  
special $super argument.

The biggest change is that all classes (as in the objects returned by  
Class.create(), not instances of those objects) now have a method  
named "addMethods."  This method takes a single argument, an object  
whose properties become instance methods and properties for all  
instances of the class.

For example, in 1.6.0_rc0, where you'd write:

   var Foo = Class.create();
   Class.extend(Foo, { /* instance methods */ });

We've changed this so you now write:

   var Foo = Class.create();
   Foo.addMethods({ /* instance methods */ });

As in 1.6.0_rc0, you can still add instance methods directly from  
Class.create:

   var Foo = Class.create({ /* instance methods */ });

Also unchanged from 1.6.0_rc0, you can inherit from a superclass by  
passing the class as the first argument to Class.create (and you can  
optionally specify instance methods afterwards):

   var Bar = Class.create(Foo);
   var Baz = Class.create(Foo, { /* instance methods */ });

Internally, Prototype calls addMethods on the newly created class to  
add instance methods passed to Class.create.

Finally, we've modified Class.create to take a variable number of  
arguments, so you can now specify multiple collections of instance  
methods to add to the class, in order.  This is useful for adding  
mixins to the class before defining your own methods:

   var Bar = Class.create(Foo, Enumerable, SomeMixin, { /* instance  
methods */ });
   var Baz = Class.create(Enumerable, { /* instance methods */ });

1.6.0_rc1 will be released very soon with these changes, and while we  
can't make any guarantees, we've no plans to change the API before the  
final release of 1.6.0 (particularly since these changes are being  
documented right now in Christophe Porteneuve's upcoming "Prototype &  
Scriptaculous" book).

-sam

  smime.p7s
3K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.