lundi 16 août 2021

How to compare single item with mutiple items

How can I avoid repeating single variable inside an if to compare it with mutiple variables or, for example how can I avoid repeating mutation.type

const targetNode = documents.getElementsByClassName("container");
const = {attributes : true , childList : true , subtree : true};

const callback = (mutation,observer)=>{
   for(const mutation of mutationList){
      if(mutation.type === 'childList' || mutation.type === 'subtree' && mutation.type === 'attributes'){
//doing something 
}
}
}

I don't wanna repeat mutation.type all the time inside an if , not only in this case but also for further coding

Aucun commentaire:

Enregistrer un commentaire