Forums

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

Home Forums JavaScript Code school – plugin implementation

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #179225
    Kuzyo
    Participant

    Hi guys.
    I go through code school courses – and try to implement exercise by myself, but found a problem – feel that something very simple and watched video again and again. I can’t find solution. Can somebody point me where the problem is.

    Here is codepen – http://codepen.io/Kuzyo/pen/lChow?editors=001

    Console shows – Undefined is not a function :(

    #179228
    Kuzyo
    Participant

    Wow. Thanks it works fine, but how it works here http://i.imgur.com/yDbUHD5.png

    #179232
    __
    Participant

    the callback [for .each] is fired in the context of the current DOM element, sothis refers to the element.
    —api.jquery.com/each

    That’s always been my experience: if I want a jQuery object with the element, I need to make one (like $(this)). @Kuzyo, are you saying that the code shown in your image does work? I’m not exactly clear on what you’re asking.

    #179248
    Kuzyo
    Participant

    Yes , it’s screen from code school video tutorial, that is marked as right :)

    Thanks for explanation!

    #179515
    __
    Participant

    I think Kuzyo was asking why the code in the image worked while the code in his codepen did not.

    That’s what I thought as well — however, the code in his image does not work, hence my confusion. Just because it is “marked as right” doesn’t mean it is.

    #186107
    greenhulk01
    Participant

    Thank you. I’ve just started to do the same thing with code school and came across the same issue – guess that is why it is always best to try the code out yourself rather than just using the codeschool editor.

    #186108
    greenhulk01
    Participant

    I think Kuzyo was asking why:

    “this.each(function() {”

    …part of the code worked when:

    “var vacation = this;” …didn’t.

    So should we not change it to be “$(this).each(function() {“?

    http://jsfiddle.net/ree6ueqd/25/

    #186144
    __
    Participant

    I think Kuzyo was asking why: this.each(function() { …part of the code worked when: var vacation = this; …didn’t.

    This is just a misunderstanding about this. this is the context that the current function is executing in. In the this.each part, this is the jQuery plugin. In the iterating function, however, this is the individual DOM element that the jQuery object passes in.

    more

    Another example of why you need to learn javascript and not just jQuery. (Not accusing you of this; just a general observation.)

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