What is the correct fix?
function tag(name) {
this.name = name;
}
const t = tag('box');
console.log(t.name);
- Construct it:
const t = new tag('box') - Construct it:
const t = call tag('box') - Add
return this;at the end oftag - Rename the parameter from
nameton
Without
Play Problem Solving ▸
new the call has no fresh this, so it returns undefined.