2009/9/8 T.J. Crowder <t...@crowdersoftware.com>:
>
> Hi all,
>
> I've taken a break from porting documentation from Mephisto into the
> source (zzzzzz) to do a first take on implementing the new
> supercalls!  Here's the commit in a branch in my repo:[1]
>
> That commit includes the code, documentation, and unit tests. The old
> class unit tests are still there (I've just renamed them "oldclass",
> though not properly from a git history POV I just realized) so we
> continue to test the old style until we remove it, which I would
> assume would be a couple of versions after introducing the new one.
> I've also added tests to prove that you can mix the two styles (derive
> from an old-style using the new style, or vice-versa), not that I
> recommend doing that. Apologies in advance if I'm out on a limb
> stylistically; I tried to fit in (inline vars! yuck!). If I've gone
> astray, please let me know.
>
> As you can see, the implementation in the Prototype code is dead
> simple, and yet the new supercalls are easy to use, particularly if
> you're already sold on the benefits of using named rather than
> anonymous functions (or if you don't care how phenomenally slow
> `arguments.callee` is).
>
> This gist[2] contains a basic performance comparison page.  The change
> really is dramatic, even if you use arguments.callee -- but it's mind-
> blowing if you use named functions (thanks, kangax, for pointing that
> out!).
>
> About dynamism:  Coming from the compiled language world, I would
> never have thought to handle people adding methods to classes on-the-
> fly AFTER the class may have been derived; thank you to Tobie for
> pointing out that requirement.  The code correctly handles defining
> new methods and redefining methods, ensuring that everybody is linked
> up correctly.  (That turned out to be trivial.)  But I have a couple
> of questions for you dynamic types:
>
> 1) Does it need to support _removing_ a method entirely? (Currently
> does not; easy to add.)
>
> 2) Does it need to handle edge cases where a name is defined on
> classes but is not a function (e.g., a class variable), but then we
> REdefine it to be a function? Or vice-versa (replacing a function with
> a non-function)? (Currently does not handle it; will complicate the
> code somewhat.)
>
> I can just about imagine (1), but frankly if you're doing (2) I think
> you need to revisit what you're doing! :-)
>
> [1] 
> http://github.com/tjcrowder/prototype/commit/79d3e1dfd32220299f0a5aceacfc6fd3ffa2a089
> [2] http://gist.github.com/182817
>
> Comments/suggestions/jeers welcome.  (Well, no, not jeers.)
>
> -- T.J.
>
> On Sep 8, 9:28 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
>> Hi Jim,
>>
>> > Perhaps I would do:
>>
>> > var B = Class.create(A, {
>> >   nifty: function(){
>>
>> >     var $super = this.nifty.$super.bind( this );
>> >     // $super refers to A.nifty() bound to this
>> >         $super();
>> >   }
>>
>> > });
>>
>> > [1] Please correct if this is wrong!
>>
>> You need to leave out the "this." and use a named function instead;
>> see my note to Allen for the details.  You can use #bind if you want
>> to, but in my experience you're typically only making a single call to
>> the superclass method, so it's not really worth the overhead.  But
>> here's what it would look like:
>>
>> var B = Class.create(A, (function(){
>>
>>   function nifty(){
>>     var $super = nifty.$super.bind( this );
>>     // $super refers to A.nifty() bound to this
>>     $super();
>>   }
>>
>>   return {nifty: nifty};
>>
>> })());
>>
>> -- T.J.
>>
>> On Sep 8, 8:52 am, Jim Higson <j...@wikizzle.org> wrote:
>>
>>
>>
>> > On Tuesday 08 September 2009 03:57:13 Allen Madsen wrote:
>>
>> > > TJ,
>> > > I guess I don't understand why it wouldn't work. I'll illustrate how I
>> > > understand it and you correct me where I'm wrong.
>>
>> > > var A = Class.create({
>> > >   nifty: function(){}
>> > > });
>>
>> > > var B = Class.create(A, {
>> > >   nifty: function(){
>> > >     this.nifty.$super(); // refers to A.nifty()
>> > >     //this.nifty(); //would cause recursion
>> > >   }
>> > > });
>>
>> > Wouldn't you have to do this to preserve scope?
>>
>> > this.nifty.$super.call( this );
>>
>> > Myself, I've never liked the .call syntax much because I mistake it with
>> > apply: the two words seem arbitrary. But, yeah, I can see that pre-binding
>> > every overridden method of every object would be a big overhead.
>>
>> > Perhaps I would do:
>>
>> > var B = Class.create(A, {
>> >   nifty: function(){
>>
>> >     var $super = this.nifty.$super.bind( this );
>> >     // $super refers to A.nifty() bound to this
>> >         $super();
>> >   }
>>
>> > });
>>
>> > [1] Please correct if this is wrong!
>>
>> > --
>> > Jim
>> > my wiki ajaxification thing:http://wikizzle.org
>> > my blog:http://jimhigson.blogspot.com/
> >
>

I'm getting an error in Chrome when I click "Test functionality" ...

   Test loops:  (suggest about 5,000 for IE, 200,000 for Chrome,
100,000 for Firefox or Safari)
GOOD: OP(hi)
GOOD: OP(hi) < OC
GOOD: OP(hi) < OC < OGC
GOOD: NP(hi)
Exception: TypeError: Cannot call method 'call' of undefined

In FireFox ...

Test loops: (suggest about 5,000 for IE, 200,000 for Chrome, 100,000
for Firefox or Safari)
GOOD: OP(hi)
GOOD: OP(hi) < OC
GOOD: OP(hi) < OC < OGC
GOOD: NP(hi)
Exception: TypeError: nifty.$super is undefined

and in IE ...

   Test loops:  (suggest about 5,000 for IE, 200,000 for Chrome,
100,000 for Firefox or Safari)
--------------------------------------------------------------------------------
GOOD: OP(hi)
GOOD: OP(hi) < OC
GOOD: OP(hi) < OC < OGC
GOOD: NP(hi)
Exception: [object Error]


I ran ...

git clone git://github.com/tjcrowder/prototype.git crowder

to create a new local copy before doing a rake dist (did the
submodules bit too).

Seems I've got the standard version and not TJ's.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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

Reply via email to