vendredi 24 novembre 2017

How to put computed functions inside switch statement?

Can anyone please help me putting the following if else into switch statement ??

var computed ={
idOnly : function () {},
classOnly : function () {},
selectAllElements: function () {},
eitherOne : function () {}
}

// From here i need to put in Switch
if (computed.idOnly(selector)) {
    var getById = document.getElementById(selectorArray[1]);
    Allelements.push(getById);
} else if (computed.classOnly(selector)) {
    var getByClass = document.getElementsByClassName(selectorArray[1]);

    computed.selectAllElements(getByClass, Allelements);
} else {
    var getByTags = document.getElementsByTagName(selectorArray[0]);

    if (selectorArray.length === 1) {
        computed.selectAllElements(getByTags, Allelements);
    } else if (selectorArray.length === 2) {
        computed.eitherOne(
            byId,
            byClass,
            byTag,
            false,
            Allelements
        );
    } else if (selectorArray.length === 3) {
        computed.eitherOne(
            byId,
            byClass,
            byTag,
            true,
            Allelements
        );
    }
}

I only need to put it inside Switch statement I will be really really thankful as i can not figure out how to do it ?

Aucun commentaire:

Enregistrer un commentaire