> Eric - I'm really not trying to test your patience... I'm just trying
> to understand.  

As most people on this group will attest, I have a lot of patience for
people who are geninely trying to understand how/why things in
TiddlyWiki work (or don't work) they way they do... and you obviously
know how to code, so at least I don't have to explain basic
programming concepts :-)

> > I think your confusion arises because there is 'window.place' variable
> > that *is* globally-defined,and usually refers to the last tiddler
> > that was rendered

> it remembers the FIRST tiddler rendered in the
> story, not the last tiddler rendered - which is ... well, weird, on
> the face of it.  Understandable now though.

ok... not exactly as I described, but the same effect... the value in
window.place is clearly a 'leftover' from some core processing, and in
any case won't be the 'place' that you want it to be :-(

> > Note that, in the absence
> > of a locally-defined 'place' variable (i.e., the one created by ILJS),
> > any reference to 'place' within your function will implicitly access
> > 'window.place'.
> Well it will find the next one "back" in the exec-context/chain -
> right?  Are we shooting for window.place or do you KNOW that is the
> only other place in the chain?  (Again, I just want to understand!)

You are correct.  The javascript scoping rules are applied to the
current call stack, working back until a suitable variable reference
is found in scope (with 'window' being the default scoping context at
the bottom of the stack).  Thus, it is possible that the value of
'place' that you are seeing in your onclick handler is actually *not*
referring to window.place, but some other 'place' variable that was
defined somewhere in the calling sequence.

again... not exactly as I had suggested, but still the same effect:
when 'place' is not defined in the local scope, the value you get is
almost certainly not the 'place' that you want it to be :-(

> > In conclusion, the correct (and only) way to get the current
> > containing tiddler from a globally-defined onclick event handler is as
> > we've already discussed:
> > var place=story.findContainingTiddler(resolveTarget(event));
>
> lol - I don't think I should do that exactly... might confuse me even
> more :)))

Just to clarify a bit: in order to avoid triggering any confusing
scoping rules, the above assignment should be done *inside* your
window.clicker() function, so that 'place' will always be defined in
the immediate local context, like this:

<script>
window.clicker=function(event) {
   var place=story.findContainingTiddler(resolveTarget(event));
   alert(place.id);
}
</script>

enjoy,
-e

P.S. This thread it is probably a bit overly technical for the general
TiddlyWiki group discussion.  Although the discussion has not actually
been directly related TiddlyWiki core development, it might be a good
idea to move any additional deep-tech programming discussion over the
the TiddlyWikiDev group, so that it doesn't become too abstruse for
the non-programming majority of the TiddlyWiki community.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" 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/TiddlyWiki?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to