re: The Prototype Pattern in JavaScript VIEW POST

FULL DISCUSSION
 

..which is equivalent to the code below, a typical class object in modern javascript. I prefer this over modifying prototype objects directly, just because it looks cleaner.

class Warrior { 
    constructor(name) {
        this.name = name;
        this.hp = 100;
    }
    bash(target) {
        target.hp -= 15;
    }
    omniSlash(target) {
        if(target.hp < 50) {
            return;
        }
        target.hp -= 50;
    }
}
code of conduct - report abuse