Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPiotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsWhy can't you use this.string and instead you're using myString.string?
Why can't you use this.string and instead you're using myString.string?
3 Answers
Barry Snowe
51,277 PointsIt might help if you post some code for context. Without seeing that code, I would suggest you think about what "this" is referring to at any point. It's a subject with some depth, but the basic jargon is that it is determined by the invocation setting. I haven't looked at the code or the challenge yet, but I suspect "this" is being avoided because it would refer to something happening in a parent function or a prototype, rather than the instance "myString" represents.
Bader Alsabah
4,738 PointsI think Barry above hit the spot with the answer - but just to perhaps add some clarity, as I have been following the video of this practice - the instructor does use the "this" keyword when referencing a property within the object declaration. In that context - "this" refers to the object and therefore using .dot notation on the object is valid. However, when she posts or console.logs the array - "this" wouldn't be referring to "myString" at that point or in that context. In fact if you try console.log with keyword "this" you will see that the value is undefined.
Steven Vallarsa
10,842 PointsI got
countWords() {return this.string.split(" ").length}
to work.