Skip to content

Commit 18485bd

Browse files
committed
[events] add events section, pass a hash not a raw value
1 parent 8335ffa commit 18485bd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
1. [Naming Conventions](#naming-conventions)
2424
1. [Accessors](#accessors)
2525
1. [Constructors](#constructors)
26+
1. [Events](#events)
2627
1. [Modules](#modules)
2728
1. [jQuery](#jquery)
2829
1. [ES5 Compatibility](#es5)
@@ -1188,6 +1189,32 @@
11881189
**[[⬆]](#TOC)**
11891190
11901191
1192+
## <a name='events'>Events</a>
1193+
1194+
- When attaching data payloads to events use a hash instead of a raw value
1195+
1196+
```javascript
1197+
// bad
1198+
$(this).trigger('listingUpdated', listing.id);
1199+
1200+
...
1201+
1202+
$(this).on('listingUpdated', function(e, listingId) {
1203+
// do something with listingId
1204+
});
1205+
1206+
// good
1207+
$(this).trigger('listingUpdated', { listingId : listing.id });
1208+
1209+
...
1210+
1211+
$(this).on('listingUpdated', function(e, data) {
1212+
// do something with data.listingId
1213+
});
1214+
```
1215+
**[[⬆]](#TOC)**
1216+
1217+
11911218
## <a name='modules'>Modules</a>
11921219
11931220
- The module should start with a `!`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated.

0 commit comments

Comments
 (0)