Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13064
    Merrill
    Participant

    I just finished my “do it yourself” VanillaPress project and have started watching the next set of videos. I noticed that in apps.js, the function init is defined within the object as a property. In the model and the view, function expression are used. However, both appear to be properties of their respective objects so I do no understand the difference or why one might be preferred over the other.

    thanks.

    #14470
    Zac Gordon
    Keymaster

    Hi Merrill,

    This is a really good question.

    What you are seeing here is a style of writing an init method that is not necessarily a best practice but is not uncommon.

    The reason for this is mostly for readability and to keep the object declaration close to the initializing method for that object. There are not really technical difference between how init and the other methods are written and init could have been written in the same way as them and vice versa.

    When I was building this project I did try to write things in a few different ways to expose us to things like this and you did a good job to bring it up here.

    I could say more, but let me know if this answers your question for you 🙂

    Sorry for the delay in response as well. Notifications plugin reactivated!

    Zac

    #14870
    Merrill
    Participant

    Thanks for your answer. I have written a bunch of jQuery for my projects and always coded the first way (in the object). Now I understand that there is a better approach.

    #14879
    Zac Gordon
    Keymaster

    Oh good! Glad that helped 🙂 Yes, some people prefer things this way..

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.