1function myNew(Constructor, ...args) {
2 // 1. Create a plain object
3 // 2. Set its [[Prototype]] to Constructor.prototype
4 // 3. Call Constructor with the new object as `this`
5 // 4. Return the object (or the constructor's return value if it's an object)
6}
7
8// Test runner — do not modify
9function solve(mode, ...args) {
10 if (mode === "basic") {
11 function Person(name, age) {
12 this.name = name;
13 this.age = age;
14 }
15 const p = myNew(Person, args[0], args[1]);
16 return p.name + ":" + p.age;
17 }
18 if (mode === "prototype") {
19 function Animal(sound) { this.sound = sound; }
20 Animal.prototype.speak = function() { return this.sound + "!"; };
21 const a = myNew(Animal, args[0]);
22 return a.speak();
23 }
24 if (mode === "instanceof") {
25 function Dog(name) { this.name = name; }
26 const d = myNew(Dog, args[0]);
27 return d instanceof Dog;
28 }
29}
30