OrderNot attempted
What new Foo() does
Order the steps JavaScript performs for new Foo(args).
Drag the rows, or use the arrows, to put them in order from first to last.
- Return the new object, unless
Fooreturned an object of its own - Call
Foowiththisbound to the new object - Link its [[Prototype]] to
Foo.prototype - Create a brand-new empty object
Show answer & explanation
Correct order:
- Create a brand-new empty object
- Link its [[Prototype]] to
Foo.prototype - Call
Foowiththisbound to the new object - Return the new object, unless
Fooreturned an object of its own
This is why methods put on Foo.prototype are shared, why forgetting new puts properties in the wrong place, and why a constructor that returns an object "hijacks" new.