Objects 10/15


No idea why this was throwing an error and making my name undefined.

Any eagle eyes to spot an error?


Here’s the error 06


arrow functions’ this is that of the surrounding scope, use a function expression instead

function() {}

first paragraph of

section Arrow Functions of

And the way you could have reasoned about this is that you can tell from the error message that this is undefined, and then you could start looking at references for how this is set (like the above links)


thanks ionatan! i was having the same issue. So we can’t use arrow functions with ‘this’?
Will ‘this’ work with the ES6 method creation?

ie would this work for:

sayGoodbye() {
return 'Goodbye!;


sayGoodbye () {
return" Goodbye, ${this.name} ";

\the “” are because it appears that ` creates a quote block.


Behaving differently isn’t the same as unusable


ah, sorry i just read your links until now. i was confused because i read that ES6 was best practice for method creation, i’ll pay careful attention with using this in the future. thanks for the reply!


Maybe they meant something else. MDN, which is a pretty reliable source, says the opposite of that – because methods involve binding the function to the object, and that’s exactly what arrow functions do not do


oh o.k. good to know. I’ll make note of that. thanks! Everything is still very new to me. I’m learning a lot though!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.