Grow your CSS skills. Land your dream job.

Nesting functions

  • # March 5, 2012 at 10:34 pm

    I’m in the middle of learning JS and jQuery. I try and create a random tool at least once a week to test how my learning is going, and this is my latest experiment: http://jsfiddle.net/joshnh/UBQvL/

    Now, originally, I was using nested for loops (http://jsfiddle.net/joshnh/UBQvL/9/), but I have since discovered that this is a bad idea for performance reasons. I have defined functions to try and get around this, but is defining a function inside another function just as bad?

    What is the best way to do what I am trying to do? Have you got any other improvements for me? Thanks in advance guys.

    Slightly related aside; should I define a function like this:

    function foo() {
    ...
    };

    Or like this:

    var foo = function() {
    ...
    };
    # March 7, 2012 at 6:44 am

    @joshuanhibbert – nice application, josh. I am also learning jquery at the moment and was wondering how you go about setting yourself projects? I am working purely off exercise files at the moment and thought it would be good to move away from that and do my own stuff. The problem is I find it hard choosing what to do. Any suggestions?

    # March 7, 2012 at 7:04 am

    Hey @tobeeornot, If you find yourself getting tired of exercise files try your hand at making plugins or your own sliders

    @joshuanhibbert
    Here’s a decent writeup about your predicament
    http://www.dustindiaz.com/javascript-function-declaration-ambiguity/

    Also this is fun https://gist.github.com/659424

    # March 7, 2012 at 7:38 am

    Great idea. Thanks @karlpcrowley

    # March 7, 2012 at 8:09 am

    Fork the Fiddle. FORK! FOORRKK!!!! o/

    # March 7, 2012 at 8:45 am
    ||||
    ||||
    __/
    ||
    ||
    ||
    ||
    ""

    Fork?

    # March 7, 2012 at 10:00 am

    @karlpcrowley: I mean, make a duplicate :p
    Honestly, I don’t understand why they use the term ‘Fork’, while when clicked, the opposite is duplication, not flying cows.

    # March 7, 2012 at 10:53 am

    Ha yeah I know
    Where I come from “Fork me” is not a nice term lol

    # March 7, 2012 at 6:09 pm

    @Hompimpa LOL! You and your forking antics ;)

    @tobeeornot I struggle with finding things to create and practise with too, but any time something pops into my head (usually from a discussion with someone) I attempt to create a tool. I much prefer creating my own stuff over following tutorials, and I find that having to figure out issues on my own is the best way to learn. The other thing I do is try to recreate popular things on my own. Things like this, this, this, this, this, this, this, and this.

    Not all of those are working 100%, but feel free to play around with them!

    @karlpcrowley Thanks for those links mate, I’ll have a look at them now! Great looking fork too :D

    # March 7, 2012 at 7:19 pm

    @karlpcrowley That article explained defining functions perfectly. Thanks Karl!

    Also, that inception gist is awesome!

    # March 8, 2012 at 6:07 am

    @joshuanhibbert – thanks very much for that. I think that is really good advice. Sometimes I am keen to move on quickly after finishing tutorials and come to doubt myself later as to how much I have absorbed. I think what you are doing sounds like the best method.

    # March 8, 2012 at 4:49 pm

    @tobeeornot No worries. Good luck with your learning!

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".