const profile = {
name: 'Ana',
role: 'designer',
describe() {
return `${this.name} - ${this.role}`;
}
};
console.log(profile.describe());The method reads the current object’s properties and returns the description.
LESSON 47 OF 50
Add behavior that uses the same object’s data.
A method definition creates a function-valued property. When calling `profile.describe()`, `this` inside the method is profile.
const profile = {
name: 'Ana',
role: 'designer',
describe() {
return `${this.name} - ${this.role}`;
}
};
console.log(profile.describe());The method reads the current object’s properties and returns the description.
console.log('Ana - designer');The message is hard-coded and no method exists.
Add a describe method that returns name and role through this, then print profile.describe().
Run the code to see the result.The method keeps behavior beside the data and uses the object that received the call.
ANALYSIS REQUEST
The initial discussion is without obligation. You receive an honest recommendation, suitable stages and the factors that affect price.