Cant figure out why method is not working in _generateHours.
Getting type error can not read properly. But the method works inside another method in the same class.
These methods are for my mark up. One is calling the container markup, and the other is a mapped for the mark up inside. Doing this, so I can dynamically change some classes. It worked fine when the container was static inside index.html file and just the mapped was in one method.
For testing I created some logs. I am very lost with why it will not register weatherIconFormat method inside the _generateHours method but works inside the _generateMarkup. I logged the data without the method inside _generateMarkups and that is coming in as it should.
Github hosted page: https://bsupinski.github.io/weather_app/
Github Repo https://github.com/bsupinski/weather_app
GitHub
GitHub - bsupinski/weather_app
Contribute to bsupinski/weather_app development by creating an account on GitHub.
12 Replies
what line are you getting what error on?
The last console log
16
In hourlyView.ha
what's the full error?
It’s in the screen shot attached.
it's weird, the issue isn't that
_weatherIconFormat
isn't getting set, it's that this
is undefined in that method... That error is formatted as if you're reading a property off an undefined object:Yeah I was trying to fool around with using bind(this) but nothing was clicking together.
I think it's because you're passing
_generateHours
as an argument on line 10 in hourlyView.js
I found this stack overflow message about this getting unbound:
https://stackoverflow.com/a/59060545/1093703Stack Overflow
'this' is undefined in JavaScript class methods
I'm new to JavaScript. New as far as all I've really done with it is tweaked existing code and wrote small bits of jQuery.
Now I'm attempting to write a "class" with attributes and methods, but I'm
so that'd be:
I just stepped out will try in a bit. I tried something similar but think I had the bind this outside the parentheses. Thank you.
no worries, hope it works!
It worked, not sure why will have to research it, i thought bind (this) was more for when this is referring to something outside the scope of the class. All these methods are inside the parent class or the class it self
the SO message says it's because of passing the method around. I think passing the function around as a variable somehow loses the fact that it's actually a class method, and the binding gets lost. It's not something I knew or encountered before, though