Welcome to the Linux Foundation Forum!

05. Closure Scope example of inheritance

The wolf function definition is missing a name parameter:

  1. function wolf () {
  2. const howl = () => {
  3. console.log(name + ': awoooooooo')
  4. }
  5. return { howl: howl }
  6. }

It should be:

  1. function wolf (name) {
  2. ...
  3. }

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

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

Comments

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training