[events] add events section, pass a hash not a raw value

This commit is contained in:
Harrison Shoff
2013-07-01 12:44:41 -07:00
parent 8335ffadb4
commit 18485bd186

View File

@@ -23,6 +23,7 @@
1. [Naming Conventions](#naming-conventions)
1. [Accessors](#accessors)
1. [Constructors](#constructors)
1. [Events](#events)
1. [Modules](#modules)
1. [jQuery](#jquery)
1. [ES5 Compatibility](#es5)
@@ -1188,6 +1189,32 @@
**[[⬆]](#TOC)**
## <a name='events'>Events</a>
- When attaching data payloads to events use a hash instead of a raw value
```javascript
// bad
$(this).trigger('listingUpdated', listing.id);
...
$(this).on('listingUpdated', function(e, listingId) {
// do something with listingId
});
// good
$(this).trigger('listingUpdated', { listingId : listing.id });
...
$(this).on('listingUpdated', function(e, data) {
// do something with data.listingId
});
```
**[[⬆]](#TOC)**
## <a name='modules'>Modules</a>
- 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.