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
4 Antworten
+ 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.
+ 4
It allows you to reference the current object.
+ 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.
0
is only a reference to current object