Tuesday, October 11, 2022

A very hard to understand snippet of MDN dismitified

 


const createPet = function (name) {
  let sex;

  const pet = {
    setName(newName) {
      name = newName;
    },

    getName() {
      return name;
    },

    getSex() {
      return sex;
    },

    setSex(newSex) {
      if (typeof newSex === 'string' &&
        (newSex.toLowerCase() === 'male' || newSex.toLowerCase() === 'female')) {
        sex = newSex;
      }
    }
  };

  return pet;
}
_______________________________

See the part that is highlighted, you got shocked and think that isn't for me what kind of function is that??? Is no function is just a structure of an object , isn't of no way an function but an object with the atributes to you fill with the values of name and sex, so for this you see is separated by comma and not an colon. Rute Bezerra de Menezes Gondim 





No comments:

Post a Comment