Pages

TD : module

 Les modules en actions ! 

lien

🖋️Devoir sur table : 5 min / level 🥷

Que valent les affichages 🪛

const add10 = {
  val: 10,
  addTo: function(array) {
    return array.map(function(elt) {
      return this.val + elt;
    });
  }
};
           
🪛console.log(add10.addTo([5,10,15]));

const add10 = {
  val: 10,
  addTo: function(array) {
    return array.map( v => v + this.val )
  }
};
           
🪛console.log(add10.addTo([5,10,15]));


Cours : module

 

This

  1. let me = {

  2.   name:"dupont",

  3.   ptrMe: function() {console.log(this.name)}

  4.   }

  5.   , you = {

  6.     name:"dupond",

  7.     ptrYou: function() {console.log(this.name)}

  8.   };

  9.     

  10. me.print = you.ptrYou;

  11. me.print()


🚀me.print()





🆘this what's that 

https://docs.google.com/document/d/1TJ8-3_9copZ0o_-GsS-to9wrLJYgPhj84TE_3Nd-XJA/edit?usp=sharing



this: Objet statique

Objet statique

const counter = {

count: 0, next: function () { return ++this.count; }, };  
🥷Il est important de comprendre que this=counter dans la fonction next() par ce que on excute counter.next();

 Pipeline ! 


const counter = {

  count: 0,
  next: function () {
     ++this.count;
     return this;
  },
};


🪳Attention: 

const counter = {

  count: 0,
  next: function () {
    return ++this.count;
  },
};

let fxNext = counter.next;

console.log(fxNext());

🤢Arrow fonction

const counter = {

  count: 0,
  next: () => ++this.count
};



console.log(counter.count);


🍕TD class

 Création de la classe Pizza ! Et oui tout est pizza objet.

🍕TD

Cours : class

DS : correction


ul.insertAdjacentHTML(
  "afterBegin",
  DS.reduce(
    (acc, cur) =>
      acc + `<li data-cohorte=${cur.cohorte}>${cur.name}</li>`,
    ""
  )
);

const showInfoCohorte = function ({ target }) {
    student.innerText = target.dataset.cohorte;
};
ul.addEventListener("click", showInfoCohorte, false);

See the Pen students by SuperDupont (@SuperDupont) on CodePen.