JSFiddle - React, Tailwind, and code Playground

by Susan Delgado

JavaScript

var ATTACKS = (function (self) {
    var movesList = {
        push: "push him",
        slash: "slash him",
        cut: "cut him"
    }
    return {
        getMoves: function(att){

             return movesList.att;   
        }
    }
}(ATTACKS || {}));

var createCharacter = function(name, type, level, attack, life, maxlife, m, src){
    
    var char = {
        name: name, 
        type: type, 
        level: level, 
        attack: attack, 
        life: life,
        maxlife: maxlife, 
        moves: [],
        src: src
    }
    var makeList = m;

    Object.defineProperty(char, "moveList",{
        get: function() {
            
            for(var prop in makeList){
                console.log(prop);                
                var move =  ATTACK.getMoves(prop);
                char.moves.push(move);
            }
             return moves;
        }
    });
    return char;
}



var hero = createCharacter("pat","hero", 1, 10, 300, 300, {push:"push", cut:"cut"}, "img.png");
alert(hero.moves[0]);