re: Hey Thomas! From my testing, it looks like new will still return the object stored at the this property from the function being altered by new. F...

It's because you return a string. If you returned an object, it would be used instead.

See also

Thomas, you are sooooo right.

function createCar(color, speed) {
  this.color = color;
  this.speed = speed;
  return { motto: 'Cars are cool' };

createCar.prototype.go = function () {
  console.log('I prefer to drive ' + this.speed + '.');

const myCar = new createCar('red', 'fast');
console.log('myCar is', myCar); // will log the object with the 'motto' key :( :(

Thank you for highlighting this oddity. I'll be updating the article and including this in an upcoming post about things to be cautious of with the new keyword.

code of conduct - report abuse