Q: 4
Given the code below:
01 function GameConsole (name) {
02 this.name = name;
03 }
04
05 GameConsole.prototype.load = function(gamename) {
06 console.log( ` $(this.name) is loading a game : $(gamename) …`);
07 )
08 function Console 16 Bit (name) {
09 GameConsole.call(this, name) ;
10 }
11 Console16bit.prototype = Object.create ( GameConsole.prototype) ;
12 //insert code here
13 console.log( ` $(this.name) is loading a cartridge game : $(gamename) …`);
14 }
15 const console16bit = new Console16bit(‘ SNEGeneziz ’);
16 console16bit.load(‘ Super Nonic 3x Force ’);
What should a developer insert at line 15 to output the following message using the
method ?
> SNEGeneziz is loading a cartridge game: Super Monic 3x Force . . .
Options
Discussion
I don’t think D is right here. The curly brace after the method name in D isn’t valid JavaScript for defining prototype methods, that’s more like class syntax. B overrides the load method on the prototype properly, so all Console16bit instances pick up the change. Pretty sure B is what they want, unless I’m missing a subtlety.
My vote is B. Syntax fits prototype override, but not 100 percent sure so open to other thoughts.
B is the right one here, since
prototype.load = function() directly overrides for all instances. D just isn't valid JS syntax for prototype methods, as others mentioned. I think B is correct but curious if I'm overlooking something small.Not D, B. Official guide and JS reference both point to prototype.method = function for overrides.
It's D. I remember a similar scenario from labs where you could just define the method like that on the prototype, so D seems plausible. Not totally sure about the curly brace style but it looks workable. Anyone else pick D over B?
D kind of looks right at first but direct method syntax there actually isn't valid for prototype. Why not D?
Practice exams covered similar prototype questions, and B is what shows up most often for method override. B
I don’t think it’s B, I’d go with D. The way D is written looks like just defining the function directly fits the pattern here, even if the prototype assignment isn’t explicit. Unless I’m missing a syntax trap?
Probably B. That's the standard way to override a prototype method, fits what they're asking for.
Be respectful. No spam.