FAQ: Advanced Objects - Review


#1

This community-built FAQ covers the “Review” exercise from the lesson “Advanced Objects”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Review

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Please, what is the solution to this Find the value of “this“ in a function inside of a method.


#3

this refers to the calling object, which value is that object. As I understand it, there is no way to find the name of the instance upon which the call is made.

Like yourself, I’m just as mystified by this question as you are. Hopefully somebody with more insight/wisdom will pipe in.

Something to consider, though I’m not sure this is what we’re after…

function listAllProperties(o) {
	var objectToInspect;     
	var result = [];
	
	for(objectToInspect = o; objectToInspect !== null; 
           objectToInspect = Object.getPrototypeOf(objectToInspect)) {  
        result = result.concat(
            Object.getOwnPropertyNames(objectToInspect)
        );  
    }
	
	return result; 
}
function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

 > myCar = new Car('Toyota', 'Corolla', 2006)

 > listAllProperties(myCar)
<- (16) ["make", "model", "year", "constructor", "constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"]
 > myCar.valueOf()
<- Car {make: "Toyota", model: "Corolla", year: 2006}
function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
  this.getValues = function () {
    return this.valueOf();
  }
}
myCar = new Car('Toyota', 'Corolla', 2006)

 > myCar.getValues()
<- Car {make: "Toyota", model: "Corolla", year: 2006, getValues: ƒ}