(ES6) ES6 (2016)

EventBubbling (EB02)

   1:  //<input id="myButton" type="button" value="myButton"></input>
   2:  
   3:  const myEventWithData = new CustomEvent('myCustomEventWithData', {
   4:      detail: { message: 'Hello from custom event!', id: 777 }
   5:  });
   6:  
   7:  document.addEventListener('myCustomEventWithData', (event) => {
   8:      console.log('Custom event with data:', event.detail);
   9:  });
  10:  
  11:  const button = document.getElementById("myButton");
  12:  button.addEventListener('myCustomEventWithData', function(event){
  13:      console.log('Custom event with data received on button:', event.detail);
  14:  });
  15:  
  16:  // Dispatch the event after listeners are registered
  17:  document.dispatchEvent(myEventWithData);
  18:  



Custom Event with Data (Event listeners must be registered before the event is dispatched)

Custom event with data: Object { message: "Hello from custom event!", id: 777 }
Attempting initialization: Date Wed Mar 12 2016 21:03:56 GMT+0200 (Eastern European Standard Time)





EventBubbling context:






ES6 context:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/EB02.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>