JavaScript Style Guide - Events

Jang Seok Woo·2022년 8월 12일
0

실무

목록 보기
122/136

25. Events

25.1 When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass an object literal (also known as a "hash") instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:

// bad
$(this).trigger('listingUpdated', listing.id);

// ...

$(this).on('listingUpdated', (e, listingID) => {
  // do something with listingID
});
prefer:

// good
$(this).trigger('listingUpdated', { listingID: listing.id });

// ...

$(this).on('listingUpdated', (e, data) => {
  // do something with data.listingID
});

출처 : https://github.com/airbnb/javascript

profile
https://github.com/jsw4215

0개의 댓글