JSFiddle - React, Tailwind, and code Playground
by Cody Lindley
HTML
<script src="https://dl.dropboxusercontent.com/u/2026291/backbone/jquery-2.0.2.js"></script>
<script src="https://dl.dropboxusercontent.com/u/2026291/backbone/lodash.underscore.js"></script>
<script src="https://dl.dropboxusercontent.com/u/2026291/backbone/backbone.js"></script>
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
CSS
iframe {
height:263px !important;
}
JavaScript
//add a custom event to the Backbone object
Backbone.on('sayHi', function () {
console.log('Hi');
});
//create an eavesdropper object and extend the object with Backbone.Events
var eavesdropper = _.extend({}, Backbone.Events);
//Set eavesdropper to listen for custom sayHi event attached to Backbone object
eavesdropper.listenTo(Backbone, 'sayHi', function () {
console.log('I heard that');
});
//Trigger/Invoke the sayHi custom event
Backbone.trigger('sayHi'); //logs 'Hi' and 'I heard that'
/*Remember Backbone extended the Backbone namespace with events
(i.e. cause Backbone did this: _.extend(Backbone, Backbone.Events);)*/