$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #63

What is the correct fix?

function tag(name) {
  this.name = name;
}
const t = tag('box');
console.log(t.name);
  1. Construct it: const t = new tag('box')
  2. Construct it: const t = call tag('box')
  3. Add return this; at the end of tag
  4. Rename the parameter from name to n
Without new the call has no fresh this, so it returns undefined.
Play Problem Solving ▸