[Proto-Scripty] Re: Enumerable context - bug?

2008-10-18 Thread Tomasz Kalkosiński

On 17 Paź, 22:07, Jerod Venema [EMAIL PROTECTED] wrote:
 This is the biggest change to get used to with Javascript if you came from a
 typical OO environment. I'm going to emphasize it again for other people
 reading this thread:

Exactly. But I get your point that's JavaScript world and things go
slightly different here (more than slightly actually :D).

For OO newcomers you should add example This will NOT work below
each() in API Docs and explain why. These counter-examples helps a lot
(especially Event.stopObserving was very helpful for me - for sure it
saved a day or two).

Thank you for these detailed explanations and keep up the good work :)

Greetings,
Tomasz Kalkosiński
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@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-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Enumerable context - bug?

2008-10-17 Thread Tomasz Kalkosiński

Hey guys.

For Enumerable, according to API Docs I've found: If there is no
context argument, the iterator function will preserve the scope it
would have anyway.

I've came to that:

function Person(name)
{
this.name=name;
this.Check=Check;
}

function Check()
{
alert(Context is  + this); //Object - ok

$w(John Mike Mary Jane).each ( function (n) {
alert(each context is  + this); //Window - why?

if (n == this.name)
alert(We have same names!);
} /*, this*/ );
}

var mike = new Person(Mike);
mike.Check ();

I assumed that while I'm in Check function my context is mike
instance. But each() is invoked in Window context instead. I had to
manually add context (like you see commented /*, this*/). Is it a bug
according to API Docs : If there is no context argument, the iterator
function will preserve the scope it would have anyway?

Greetings,
Tomasz Kalkosiński
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@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-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable context - bug?

2008-10-17 Thread Tomasz Kalkosiński

On Oct 17, 3:44 pm, kangax [EMAIL PROTECTED] wrote:
 Sorry, that's just a poor wording on our side : /
 By preserve scope it would have anyway it was probably meant that a
 function is not explicitly bound to any object.

 The way you understood binding in this case is actually pretty
 intuitive to many people.

It's intuitive because it's like closures work. Now I have doubts if
my other Enumerable methods behave as I intended them to. What do
others think?

I think you should use simple example in like mine in API Docs to
illustrate it's not intuitive.

I'm sad :(
Tomasz Kalkosiński


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@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-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable.each return and throw

2008-10-09 Thread Tomasz Kalkosiński

Nah! I've just discovered Enumerable.any() and Enumerable.all(). That
should do the trick.

Sorry for hassle o

Greetings,
Tomasz Kalkosiński

On Oct 9, 10:47 am, Tomasz Kalkosiński [EMAIL PROTECTED]
wrote:
 I'm refactoring old code and I use Enumerable.each() wherever
 possible. I've came to problem like this:

 function checkSomething (arr)
     for (i=0 ; i  arr.length ; i++) {
         var c = arr[i];
         if (c == 15) return true;
     }
     return false;

 }

 My question is can I do short-circuit return from inside
 each( function (c) {...} ) ? When I do return it's just like old throw
 $continue and it's not what I mean.

 Greetings,
 Tomasz Kalkosiński
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@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-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable.each return and throw

2008-10-09 Thread Tomasz Kalkosiński

On Oct 9, 12:23 pm, T.J. Crowder [EMAIL PROTECTED] wrote:
 Or, if there's a situation where any() or all() doesn't suit, you can
 break each() loops by throwing $break.

Yes I can do it, but I cannot determine afterwards whether I've exited
iteration with throwing $break or I've iterated thru all elements.

Also scenatio of returning something different than true/false using
any() and all() is undoable with each():

function checkSomething (arr)
var succ = Succ;
var fail = Fail
for (i=0 ; i  arr.length ; i++) {
var c = arr[i];
if (c == 15) return fail;
}
return succ;
}

You cannot re-do function above using each(). All I know you can do $
(arr).all(function (c) {...}) ? Succ : Fail;.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@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-scriptaculous?hl=en
-~--~~~~--~~--~--~---