24/10
TOP - Foundation: 93%
Object Basics
Read more about object on: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Object_basics.
Great read.
Don't know if because I read about object on https://javascript.info/object. yesterday so my understanding of object feel clearer now or MDN explain easier to understand than javascript.info ( MDN's explainations often feel harder to understand than javascript.info imo )
Understand more about object property and method.
Object property is used to refer to data items inside object.
Object method refer to function inside object. (object method is still an object property though)
Learn more about this.
This refer to the current object the method is called on.
If the object has a nested object inside of it and inside of that nested object have a method with this then this here refer to the nested object, not the outer object.
Example:
const person = {
name: { first : 'John', last: 'Smith' },
lookForThis() { console.log(this) },
obj: { lookForThis() { console.log(this) }},
};
person.lookForThis() // get person object
person.obj.lookForThis() // get obj object
Top comments (0)