> On this point I have to say, It is really hard to extend prototype,
> there should be a central registry Object.Extend writes to and I
> should not have to write 20 lines of code to change the behavior of
> each in all enumerables, it should be possible to do this in one line
> of code .

I guess, I'm missing how you're thinking of handling it.

Are you hoping to open the function and add just the intended lines to
it?
You'll either have to update your own copy of prototype.js or just
override it:

Object.extend(Enumerable, {
each : function (...) {...}
});

Last I checked, Object.extend doesn't check if a child is defined
before redefining.
So, that shouldn't be too difficult.


> so all three
>
> each (function, binding)
>
> and
>
> each (binding, function)
>
> and
>
> each (function)
>
> work with my extension.
>
> Nothing lost only the api is more flexible with a minimal performance
> hit.

Actually, regularity can also take a hit with this.
IMO, this contradicts the general assumption of how javascript
functions are defined:

function (arg0orN [, arg1orN [, ... [, argNor1or0]]])   // confused,
yet? I am
vs.
function (arg0 [, arg1 [, ... [, argN]]])


This is just my opinion...
It would make more sense to have a separate function:
each ( function [, binding] )
eachOf ( binding, function )  // or something similar

Sound reasonable? Plausible?


> > ... and IMHO
> > you'd be better served just getting used to it as you will see it in any
> > prototype user's work, should you ever be part of a bigger team.
>
> Jesus, this is not a pissing contest, I'm just making a suggestion
> here.

Generally speaking, most "suggestions" are posed as questions: "What
do you think about [suggestion]?"
Versus, "this is BS...they're idiots...they should do it this way
cause I think it's better."
At least, that's the tone/attitude I got out of your aforementioned
blog post.

When you start by "pissing" on someone else, it's probably not a safe
assumption to expect a pleasant response.

Besides...
Ryan wasn't "pissing." He was stating a recommendation -- one I have
to agree with.
You may convince a team to adopt your extensions. But, if they don't,
you'll be stuck using a format that's not aesthetic to your eyes.

- Jon L.

On Feb 7, 11:08 pm, sambo99 <[EMAIL PROTECTED]> wrote:
> On Feb 8, 3:34 pm, "Ryan Gahl" <[EMAIL PROTECTED]> wrote:
>
> > Completely disagree. First of all, you don't need the parentheses in your
> > first example. You can simply do stuff like "function() {...}.bind(this)".
>
> Actually if you run
>   window.hello = "ninja";
>   var MyClass = Class.create ({
>     test: function()
>     {
>       this.items = $A([1]);
>       this.hello = "hello";
>       this.items.each(function(i)
>         {
>             alert(this.hello);
>         }).bind(this);
>     }
>   });
>
> you get a ninja!
>
> > Secondly, in your conclusion you are assuming that you will always _need_ to
> > correct scope, when in fact you only need to do this if you want to use the
> > keyword "this" within the iterator. There are many times when you would not
> > be correcting scope at all, so then are you suggesting that we pass in null
> > as the first param?
>
> Wrong, perhaps I should re-word it. I conclude that the API should be
> more flexible:
> "I basically change the each function so it can be called with the
> object name as the first param while maintaining backwards
> compatibility."
>
> so all three
>
> each (function, binding)
>
> and
>
> each (binding, function)
>
> and
>
> each (function)
>
> work with my extension.
>
> Nothing lost only the api is more flexible with a minimal performance
> hit.
>
> > Thirdly, and most importantly... just create a wrapper if you want this
> > syntax... and get used to creating wrappers where you want/need a new API.
>
> On this point I have to say, It is really hard to extend prototype,
> there should be a central registry Object.Extend writes to and I
> should not have to write 20 lines of code to change the behavior of
> each in all enumerables, it should be possible to do this in one line
> of code .
>
> > //cache old method for calling within the override
> > Array.prototype._oldEach = Array.prototype.each;
> > Array.prototype.each = function(scope, iterator) {
> > if (scope)
> > iterator = iterator.bind(scope);
> > return this._oldEach(iterator);
>
> > };
>
> > .bind(this) is not ugly by the way. It's a very elegant solution, and IMHO
> > you'd be better served just getting used to it as you will see it in any
> > prototype user's work, should you ever be part of a bigger team.
>
> Jesus, this is not a pissing contest, I'm just making a suggestion
> here.
>
> > On 2/7/08, sambo99 <[EMAIL PROTECTED]> wrote:
>
> > > I blogged about this issue here:
>
> > >http://www.samsaffron.com/archive/2008/02/09/A+cleaner+way+to+iterate...
>
> > > I think iterators look nicer when you have the scope as the first
> > > param.
>
> > --
> > Ryan Gahl
> > Manager, Senior Software Engineer
> > Nth Penguin, LLChttp://www.nthpenguin.com
> > --
> > WebWidgetry.com / MashupStudio.com
> > Future Home of the World's First Complete Web Platform
> > --
> > Inquire: 1-920-574-2218
> > Blog:http://www.someElement.com
> > LinkedIn Profile:http://www.linkedin.com/in/ryangahl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" 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/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to