version 1.0.0
module: itsa-event
maintanance: Marco Asbreuk
all modules

Object emission on Event

Preferable, you emit events on an Class-instance or object, using the helpers on its prototype. However, sometimes objects are already created and you can't change the prototype. Instead of merging the listener-helpers to every single object, you should use Event.emit to emit events.

Click on the button to make "Marco 10" save.


    <button id="buttongo" class="pure-button pure-button-primary pure-button-bordered">Save</button>
<script src="itsabuild-min.js"></script>
    // instead of loading the data (as explained in the example-source)
    // we simulate this by just creating the array.
    // so we don't need to maintain a server running for this example
    var profiles = [],

    // create 100 profiles which all can emit through their prototype:
    for (i=0; i<100; i++) {
        profiles.push({name: 'Marco '+i});

        function(e) {
            alert(' got saved');

        function() {
            // we make the 11'th element to emit the save-event:
            ITSA.Event.emit(profiles[10], 'PersonalProfile:save');
API Docs