Constructors in Review - describeMyself not showing in console log


#1


https://www.codecademy.com/courses/spencer-sandbox/3/6?curriculum_id=506324b3a7dffd00020bf661#


I think I get the exercise here but I don't understand why my new objects created (rabbit1, rabbit2, etc) are not displaying the "describeMyself" functions of each new object in the console.

Can someone explain why it's not showing?


function Rabbit(adjective) {
    this.adjective = adjective;
    this.describeMyself = function() {
        console.log("I am a " + this.adjective + " rabbit");
    };
}

// now we can easily make all of our rabbits

var rabbit1 = new Rabbit("fluffy");
rabbit1.describeMyself;

var rabbit2 = new Rabbit("happy");
rabbit2.describeMyself;

var rabbit3 = new Rabbit("sleepy");
rabbit3.describeMyself;


#2

Recall that a method needs to be invoked.

.describeMyself()

#3

Thank you. That worked!

For lack of better words, so I need to have an argument "( )" for all methods, even when there are none. Is that right?


#4

Yes, that is right. Consider,

console.log(rabbit1.describeMyself.toString())

Output

function() {
    console.log("I am a " + this.adjective + " rabbit");
}

When we leave off the parens (argument) we are referring to the string representation of the method, not the return value.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.