Well, I like Michael's syntax a little better.. It looks more
organized instead of all clumped together.. not only that, but the
function I would write for Clicked could be used over and over again.
My brain is pretty much set to run in OOP mode so anything else is
just harder for me. The way I think, this would be the most
understandable:
//The perfect syntactical fit for me :-)
var Shizzle;
$(document).ready()
{
Shizzle = new $("a");
Shizzle.animate('height', 10, 100, 1000); // height of 10 to 100
in 1 sec
Shizzle.animate('left', 0, 300, 1000);
Shizzle.css.opacity = 0.5;
Shizzle.animate('opacity', 1, 1000);
}
Anything else is going to have a steep learning curve for me.. But the
separate functions you suggested do clear things up a bit.
Thanks!
On Sep 27, 9:02 am, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> You have to use functions in that code, because you are using two callbacks,
> and that's how you do callbacks in JavaScript, with
> functions that get called later.
>
> The first callback is the outer function that gets called when the document
> is ready.
>
> The second callback is the inner function that gets called when you click an
> A tag.
>
> Is it the nested anonymous functions that are throwing you off? You can
> certainly substitute named functions if you prefer. This
> code does the same thing:
>
> $(document).ready( ready );
>
> function ready() {
> alert( 'Ready' );
> $('a').click( clicked );
> }
>
> function clicked() {
> alert( 'Clicked' );
> }
>
> But I agree with Erik: Even if you choose to use named functions in your own
> code, it would be a good idea to get comfortable with
> anonymous functions. You will see a LOT of them in jQuery code, and you don't
> want to feel dizzy every time.
>
> It's no different from setTimeout. You can code:
>
> setTimeout( function() {
> alert( 'Hello' );
> }, 1000 );
>
> or the equivalent:
>
> setTimeout( hello, 1000 );
>
> function hello() {
> alert( 'Hello' );
> }
>
> One other point: Do you have an editor that does brace/bracket/parenthesis
> matching andsyntaxchecking (not justsyntaxcoloring)?
> If not, I highly recommend the free Komodo Edit:
>
> http://www.activestate.com/Products/komodo_edit/
>
> Even if you have another favorite editor, it's worth loading your code into
> Komodo in addition, just to get thesyntaxchecking.
>
> -Mike
>
> > From: A32
>
> > I find the following example very dirtysyntax:
>
> > $(document).ready(function(){
> > alert("Document is ready")
>
> > $("a").click(function(){
> > alert("Clicked");
> > });
> > });
>
> > With all those ) and } I don't know if I'm coming or going.. Is there
> > an alternatesyntaxI can use? Do I *have* to use the "function()" all
> > the time or is there a different way? I've been away from JavaScript
> > for a long time but never seen anything like that :-)
>
> > If there's no way around it, does anybody know of a javascript
> > preprocessor that I could use a cleanersyntaxwhile developing?