Fun with Functions recursion error


#1


https://www.codecademy.com/courses/objects-ii/0/2?curriculum_id=506324b3a7dffd00020bf661#


I don't know why I am getting this error.
Oops, try again.
When testing the Person constructor your code threw the following error: InternalError: too much recursion


function Person(job, married) {
    this.job = job;
    this.married = married;
    // add a "speak" method to Person!
    this.speak= Person()
    {
        console.log("Hello!");
    };
}

var user = new Person("Codecademy Student",false);
user.speak();


#2

I figured it out.. changed this.speak= person() --> this.speak = function(). Can someone explain the difference that would be great though.


#3

I believe it's b/c Person is declared as a function already, and you can't call the function within it's function.


#4

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