There is a pattern that prevents problems that can arise if you call a constructor in JavaScript without the keyword new :
function Waffle() { if (!(this instanceof Waffle)) { return new Waffle(); } this.tastes = "yummy"; // Почему это свойство запишется в объект? // Ведь мы же уже возвратили объект из конструктора } Waffle.prototype.wantAnother = true; var test = Waffle(); console.log(test.wantAnother); console.log(test.tastes); I do not understand why the tastes property is written to instances of the Waffle class. After all, before assigning it, we returned an object from the constructor (when the constructor was called without new )
Note. The example is taken from the book "Stoyan Stefanov. Javascript. Templates"