Welcome to the Linux Foundation Forum!

05. Closure Scope example of inheritance

Options

The wolf function definition is missing a name parameter:

function wolf () {
  const howl = () => {
    console.log(name + ': awoooooooo')
  }
  return { howl: howl }
}

It should be:

function wolf (name) {
 ...
}

Otherwise when you try and run the example, node says:

Rufus the dog: woof                                                                                                                                   
/home/user/Documents/nodejs_app_dev/labs/ch-5/examples/functional-prototypal-inheritance/closure.js:3                                                  
    console.log(name + ": awoooooooo");                                                                                                               
                ^                                                                                                                                     

ReferenceError: name is not defined

Comments

Categories

Upcoming Training