not to create an object with new Constructor

javascript

Solution

I think what you're supposed to do is throw an exception.

function Monster(name, hp) {
    if (hp < 1) {
        throw "health points cannot be less than 1";
    }
    this.hp = hp;
    this.name = name;
}

var m = new Monster("Not a good monster", 0);

Problem

Is there an option to not create an object with particular condition within constructor, e.g. ``` function Monster(name, hp) { if (hp < 1) { delete this; } else { this.name = name; } } var theMonster = new Monster("Sulley", -5); // undefined ```

Original source