JSFiddle - React, Tailwind, and code Playground
JavaScript
var personImageC = new PersonImageCorrect("correct", "image_url");
var personImageCD = new PersonImageCorrectDesired("correct", "image_url");
var personImageW = new PersonImageWrong("wrong", "image_url");
function PersonImageCorrect(a, b)
{
this.img = document.createElement('img');
this.img.alt = a;
this.img.src = b;
return this.img;
}
function PersonImageCorrectDesired(a, b)
{
this.img = document.createElement('img');
this.img.alt = a;
this.img.src = b;
return this;
}
function PersonImageWrong(a, b)
{
img = document.createElement('img');
img.alt = a;
img.src = b;
return this.img;
}
console.log("Correct, 1 (returning 'img'): ");
console.log(personImageC);
console.log("Correct, 2 (returning filled desired object with .img prop): ");
console.log(personImageCD);
console.log("Wrong, 1 (empty PersonImageWrong object): ");
console.log(personImageW);
console.log("Wrong, 2 (undefined): ");
console.log(personImageW.img);