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 prototype-core@googlegroups.com
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