Home › Forums › JavaScript › Code school – plugin implementation
- This topic is empty.
-
AuthorPosts
-
August 15, 2014 at 12:43 pm #179225KuzyoParticipant
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 :(
August 15, 2014 at 1:11 pm #179228KuzyoParticipantWow. Thanks it works fine, but how it works here http://i.imgur.com/yDbUHD5.png
August 15, 2014 at 2:20 pm #179232__Participantthe callback [for .each] is fired in the context of the current DOM element, so
this
refers to the element.
—api.jquery.com/eachThat’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.August 15, 2014 at 10:30 pm #179248KuzyoParticipantYes , it’s screen from code school video tutorial, that is marked as right :)
Thanks for explanation!
August 18, 2014 at 11:08 am #179515__ParticipantI 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.
October 13, 2014 at 6:03 am #186107greenhulk01ParticipantThank 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.
October 13, 2014 at 6:09 am #186108greenhulk01ParticipantI 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() {“?
October 13, 2014 at 3:18 pm #186144__ParticipantI 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 thethis.each
part,this
is the jQuery plugin. In the iterating function, however,this
is the individual DOM element that the jQuery object passes in.Another example of why you need to learn javascript and not just jQuery. (Not accusing you of this; just a general observation.)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.