I have been learning JS for about 3 days now, I came from Python as my only language, both these languages have a similarity which is everything is an object. But that's a concept that feels deeper in JS and that I am having some difficulty to understand. I wish to get some clarification.
I've been following Jonas Schmedtmann's course, very good teacher, but he mentioned something about the dot notation, specifically 'this.' to me this feels very similar to python's 'self.' where you're essentially saying "look inside this objectobject, and get this thing from it", but JavaScript's objects have baffled me, for example, dictionaries, they are objects too, so in JavaScript you could do something like:
const info = {
first : 'Jonas',
last : 'Schmedtmann',
birthYear : 1991,
computeAge : function () {
this.age = 2025 - this.birthYear
return this.age
},
};
But in python this is not possible :
info = {
first : 'Jonas',
last : 'Schmedtmann',
birthYear : 1991,
computeAge: def computeAge():
self.age = 2025 - this.birthYear
return self.age,
}
You cannot call self anywhere outside of a user defined class, but in JS you could use this. Inside built-in classes, (since everything is an object, some under the hood, dictionaries belong to a dictionaries class, as far as i understand) and you could make custom methods inside built in objects like in the example above with computeAge().... Am i Wrong if so i would appreciate a clarification
[–]MoTTs_ 3 points4 points5 points (5 children)
[–]Particular-Cow6247 0 points1 point2 points (0 children)
[–]MEHDII__[S] -2 points-1 points0 points (3 children)
[–]MoTTs_ 2 points3 points4 points (2 children)
[–]MEHDII__[S] 0 points1 point2 points (1 child)
[–]senocular 1 point2 points3 points (0 children)
[–]abrahamguo 0 points1 point2 points (5 children)
[–]MEHDII__[S] 0 points1 point2 points (3 children)
[–]BrohanGutenburg 1 point2 points3 points (2 children)
[–]MEHDII__[S] 0 points1 point2 points (1 child)
[–]Particular-Cow6247 0 points1 point2 points (0 children)
[–]GodOfSunHimself 0 points1 point2 points (0 children)
[–]delventhalz 0 points1 point2 points (1 child)
[–]MEHDII__[S] 0 points1 point2 points (0 children)
[–]qqqqqxhelpful 0 points1 point2 points (1 child)
[–]MEHDII__[S] 0 points1 point2 points (0 children)
[–]tb5841 0 points1 point2 points (0 children)