Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Nesting functions

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #36999

    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() {
    ...
    };
    #98341
    tobeeornot
    Member

    @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?

    #98349
    tobeeornot
    Member

    Great idea. Thanks @karlpcrowley

    #98418

    @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

    #98429

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

    Also, that inception gist is awesome!

    #98472
    tobeeornot
    Member

    @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.

    #98520

    @tobeeornot No worries. Good luck with your learning!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.