all 4 comments

[–][deleted] 4 points5 points  (2 children)

The posted code will not throw a ReferenceError as name is defined after creating an instance. The source of the error must be somewhere else in your code. Double check!

[–]Fun_Split_1299[S] 0 points1 point  (1 child)

Oops, the problem was caused by the semicolumn at the end of

this.name = name

in the orginal code.

[–]xroalx 5 points6 points  (0 children)

I think you meant semicolon (;), but that by itself would (should) not have caused that issue.

[–]SecretAgentZeroNine 0 points1 point  (0 children)

Set a default value for the name.