Excuse me, I have a little problem with javascript to understand the utility "this", in fact I still can't understand what it is | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Excuse me, I have a little problem with javascript to understand the utility "this", in fact I still can't understand what it is

Excuse me, I have a little problem with javascript to understand the utility "this", in fact I still can't understand what it is for. please enlighten me please

14th Jan 2020, 10:32 PM
Dylan Ahiwa
Dylan Ahiwa - avatar
4 Answers
+ 5
https://www.w3schools.com/js/js_this.asp C'est un peu difficile a apprendre au debut. Supposont que tu as un object voiture, avec: var voiture = { couleur = "rouge", marque = "bmw", ma_couleur_est = function(){ return this.couleur; } } this veux dire l'object lui meme, donc dans ce cas, this est la voiture, et this.couleur et this.marque sont ses attribus.
14th Jan 2020, 10:35 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
It allows you to reference the current object.
14th Jan 2020, 10:35 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
This is basically used for classes and objects. It's basically a way of a object referencing itself; for example, in classes, you won't know what the object name is(since objects are just instantiated from classes), which means it will be useful to have the this keyword, so that you can have multiple objects be able to reference their own attributes.
14th Jan 2020, 10:44 PM
Jianmin Chen
Jianmin Chen - avatar
0
is only a reference to current object
15th Jan 2020, 12:45 AM
alexei rojas
alexei rojas - avatar