JSFiddle - React, Tailwind, and code Playground

by jcubed111

JavaScript

class Spell{
	constructor() {
		this.isSpell = true;
	}
    
    test() {
    	alert(this.hello);
    }
}

function makeSpellClass(name, props, cb) {
	let result = class extends Spell {
    	constructor() {
        	super();
            _.extend(this, props);
        }
    };
    
    result.prototype.castEffect = cb;
    
    Object.defineProperty(result, 'name', {
        value: name,
        writable: false
    });
    
    return result;
}

let C = makeSpellClass('testSpell', {hello: 7}, a => alert('casted'));
let D = makeSpellClass('testSpell', {hello: 7}, a => alert('casted2'));
alert(C.name);
let c = new C();
let d = new D();
c.test();
c.castEffect();
d.castEffect();