+ 3

JAVASCRIPT EXPERTS: Please, can someone explain the "this" keyword? I only see redundancy!

I have looked at-no...I've studied until my eyes were ready to bleed-8 different sources (incl here, Eloquent, JSinfo, and MDN) and none are making sense! I will try to explain what I see via analogy: "This is a cat. We know it is a cat because cats are cats. So, let's assign a new name to the cat: we will. call it…cat!" Really, it is how I see it. If that's the case, what is the point? This.name = name?! But it was already called name in the first place! Ohhh, I have such a headache from...THIS! Help? 😣

14th Dec 2017, 11:28 PM
Michael
Michael - avatar
13 Réponses
+ 6
I'm no expert in this with JS and it is different from the C++ I am a expert in. However, the source that best made sense to me is this one. https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work
14th Dec 2017, 11:50 PM
John Wells
John Wells - avatar
+ 12
Not an expert, just a learner. Check the below article. it helped me get up to speed in using it. Ask if you have any doubts still remaining. We sololearners will try our level best to solve them. https://zellwk.com/blog/this/ About why should you use it. Check below. https://zellwk.com/blog/should-you-use-this/
16th Dec 2017, 6:19 AM
Lord Krishna
Lord Krishna - avatar
+ 10
THIS is more simple than you think! THIS is simply This. when you put a this you are simply sure that you refer to This and not something else. class A{ int Aparam1 float Aparam2 ... A(int Aparam1,..,.) <---you are passing those values in constructor.. whit the same signature!! { Aparam1=Aparam1 .... compiler says.. whut tha hell is that!? its not an error but... so you type instead.. this.Aparam1=Aparam1 and compiler says.. ok you are passing Aparam1 value to (Aparam1 parameter of THIS object i'm constructing) Thats all, the rest is just a more deeper and complicated apply of.. This! lol hope it helps
17th Dec 2017, 9:30 PM
AZTECCO
AZTECCO - avatar
+ 9
@Michael, please don't take it personal mate, as Mr. Wells said, nobody is guaranteed to get an answer for each of their questions, nor will they get up votes on it. Besides, having "JAVASCRIPT EXPERTS" in the title also sounded an expert answer is expected, and some may not feel confident enough to step forward to give an opinion, so they took a step back instead, I was one of them actually. Other than that, well, it's weekend, and for Christian friends, they probably are busy preparing Christmas, some student friends, probably having an exam, etc. etc. The bottom line is, nobody really meant to ignore, but they just happen to be busy somewhere doing something. A new year is coming, I wish it would bring you, me and everyone something better, this may sound BS, but I do wish it could happen. Best regards, Now don't say I ignore you ... : )
16th Dec 2017, 4:55 AM
Ipang
+ 9
@Michael, that's what friends are for, well, I actually am glad you spoke out how you feel rather than keeping it to yourself, and sorry if this friend didn't give a good answer or as expected, like everyone else, me too have limits : ) Thanks for sharing, and the question, had you not bring it up, probably I would never learned. Thanks to all who contributed to this discussion, and Mr. Wells for initial movement, really appreciate all that.
16th Dec 2017, 6:03 PM
Ipang
+ 6
Michael, I can't promise you people will see your questions. I only did because I routinely look for unanswered questions. Yours was back a few hours. Most people here wouldn't be able answer this question so most wouldn't try. If you wish, join us here. You can IM me there with your future questions. https://www.sololearn.com/Discuss/689391/?ref=app
16th Dec 2017, 12:12 AM
John Wells
John Wells - avatar
+ 6
I wish I could answer your question. But I feel lacking of confident to answer this keyword correctly. It looks simple but it's a deep topic involves well versed of OOP concepts. Edited In Sololearn, majority are beginners in programming. You should try to search or post your question on stackoverflow, it should give you more comprehensive answer.
16th Dec 2017, 5:13 AM
Calviղ
Calviղ - avatar
+ 5
@Michael, you are most welcome, though, actually, I don't think I earned your sincere appreciation, as I only return here to assure you that people care still, as for the solution, others had given you what I couldn't. Well, I guess you have a point on how people change these days, the "me first" ideology, but surprisingly, there's always an odd chance for us to meet different people, and different mindset. I guess it's a tough year for most of us anyway, in different ways. Let's just keep that little hope the next years would be better than the previous, for everything and everyone. I'm glad you have worked something out from our little discussion here, in terms of code, and I strongly encourage you to post that code wherever appropriate around the neighborhood, so the knowledge can spread, I'm pretty sure there are loads of people here who probably still have the doubts regarding the 'this' keyword. Finally, I apologize if there's any misspellings or incorrectly formed sentence, as I am not English speaking by nature (Thanks to Google Translate) Ipang
17th Dec 2017, 8:34 PM
Ipang
+ 4
Your question also helped me get perspective on 'this'. It isn't at all like the other languages I do know and I might have never learned that without this question so thank you!
16th Dec 2017, 5:48 PM
John Wells
John Wells - avatar
+ 3
Wow. ***ONE? ONLY ONE PERSON*** answered my question. I know it cannot _possibly_ be that all these Web Designers, Devs, Gurus, Sensei/Sifus were just faking it and/or lying about their *'Kung Fu being the best.'* So, it must be pretty much what I thought all along. Actually, it is worse than I thought, and _that_ is saying something! All these people asking questions all the time. It's what this is for. I have asked other questions in the past and gotten the same number (1), or worse, **none at all.** Yes, it makes a person feel all warm, welcomed, and fuzzy feeling. I must point out that that was sarcasm. I know that people have a hard time around this time of year. I am most certainly one of them. But this year is worse than usual, with the exception of last year. Last year, I was in the hospital for...some similar problems. I am slightly better (or was) this year. But this is just one of a few that have (with one kind exception which I appreciate) ignored me. And why not? I hardly contribute, mostly because I have a hard time understanding a lot of things like this...the whole lot, not just Web related. I have only been able to finish a couple of tutorials and that was months ago. I try, but again, my programs suck and are not worth anyone's time. I think the most upvotes I have ever gotten at one time is 7 or 8. LOL! I can't even get 10 people to notice the fact that I am trying and to say, "Good job." Not even that much effort is needed. «click» done. Not even worth 10 of those. I really could have used a bit more than 1 response. But, I suppose truth is truth: you can't make sh** (crap/feces/etc) shiny and pretty. Worthless is just that, nothing more. Just worthless. I mean what am I even doing here?
15th Dec 2017, 11:48 PM
Michael
Michael - avatar
+ 3
Thank you, "JAVASCRIPT EXPERTS" for answering after all. Those who did answer will see the humor in that thank you. No, but seriously, I didn't get a lot of replies (5 + 1 person twice= 6) and I am going to comment on those. Forgive me though for not being able to name each post source as it is rather difficult for me to do such back and forth tasks. Not a stupidity thing, more a moderate to severe case of ADD (not ADHD. I am not super impulsive, but more the 'space cadet' type). Case in point, it took a couple of minutes to remember what I had been talking about before the tangential excursion. I really appreciate everything you guys said. And I get it that the "this" keyword is not an easy thing to explain, understand, and worse yet, put into use. And I don't want you guys to think that I was being super sensitive (sensitive, sure), because this was not the only time that this has happened. I have been experiencing this for months now. Oh, of course, every once in a while I DO get some answers/replies and a few up votes. But even those exceptions are not too far from the norm. I still have fewer than 10 up votes on any post, ever. I still get no more than 10 answers (one exception, I got 11. lol). But really, that was the least of several other things that I had mentioned. I am really sorry for sounding so down and "poor me," and such. I didn't realize that until this morning upon rereading it a few times. That said, I have already hinted that it was not intended to sound that way. More like a WTF?! sort. Anyway, I am appreciative of your efforts, time, and kind words. Thank you, guys. Every one of you helped me get some perspective on "this". 😂😂 Sorry, I just had to do it. That was a perfectly set up PUNny situation! Thanks again! Michael
16th Dec 2017, 5:34 PM
Michael
Michael - avatar
+ 3
HEAR, HEAR! I appreciate you both, Mr. Wells and Ipang. Thank you both for the wonderful outreach and outpouring of friendship. And especially at this time of year when very many people are caught up in their own problems and so, inadvertently, they are caught up in their own heads, y'know? Oh, there are also a few who, knowing exactly what is going on around them, still CHOOSE to be a knucklehead, saying things like, "Hey, I've got my own stuff to deal with. I have no time to help you out." Yeahhh, but the thing is that most of us are in the same place with our own things and little or no time to help anyone else. But it is the ones like you two (John Wells and Ipang) who, in spite of having no time and having your own problems, YOU HELP OUT ANYWAY! (Sorry for the CAPS, I have no other way to emphasize the words I want to. I tried to use a simple form of markdown, but I guess it doesn't work in here.) But anyway, I am honored to have met you both and I am forever grateful for you guys. Thank you and (I hope nobody takes offense, because I only mean it from the heart… but, being a Christian (not one who pushes it onto others, or excludes any other beliefs, creeds, philosophies, or religions, but just Christian, trying to be and make others happy), I want to say that I hope you all have a great Christmas, Chanukah (I hope I spelled it correctly), Kwanzaa, and Happy Holidays! Thanks again guys. Oh, good news. I figured out the "this" problem and wrote a program for others to see in a way that does not make it all complicated and confusing. I don't know why it was so, but everyone kept making it cryptic almost on purpose! So, I posted it yesterday, or about 20 hours ago if you guys are interested. Okay, enough typing and sorry I can't seem to produce a short note. lol Michael C
17th Dec 2017, 7:29 PM
Michael
Michael - avatar
+ 2
Merry Christmas, Michael. I will look for your program. I truly suggest joining on discord. You can ping everyone claiming a language so they can see if they can help.
17th Dec 2017, 8:41 PM
John Wells
John Wells - avatar