Object methods "this"
Object methods "this"
To access the object, a method can use the this keyword.
The value of this is the object "before dot", the one used to call the method.
Method examples
Let user = {
name: "John",
age: 30
};
*!*
user.sayHi = function() {
alert("Hello!");
};
*/!*
user.sayHi(); // Hello! A function that is the property of an object is called its method.
Method shorthand
Related concepts
→
Object methods "this"
→
Semantic portal