>
> 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!


You have something slightly wrong with the above, vs. what I was suggesting.
You are placing your .bind(this) after the close paren of the .each() call.
What I said was simply place it after the end curly bracket of the function
itself... so like 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));
   }
 });

The above method of .bind(this)'ing an anonymous function is very common.

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.


Exactly... I did say "IMHO", so you know, take it with a grain of salt as it
is my humble opinion. I am a proponent of prototype remaining as baseline as
possible and preach "wrap, wrap, wrap" on these lists all the time. And I
wasn't pissing, dude, just... you're in the prototype core list, and I'm
arguing against your bit, saying that .bind(this) should remain "the way" to
correct scope when needed, and you'd server yourself well (IMHO!!) to learn
to love it :)


-- 
Ryan Gahl
Manager, Senior Software Engineer
Nth Penguin, LLC
http://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