<script type="text/javascript">         
        var object = {
            observe:function(callback) {
                alert("observing... ("+callback+")");  
                object.listener = callback;
            },
            test:function(message) {
                alert("Message: "+ message);
            },        
            listener:function() {
                alert("No callback specified");
            },
            dispatch:function () {
                alert("Dispatching... ("+ object.listener + ")");
                object.listener();
            }
        }                
        
        function addCallbackFromJavascript()
        {
            object.observe(function() {
                alert("Event Fired (from Javascript)!");
            })
        }
    </script>
    
    <div><a href='#' onclick='object.dispatch()'>Fire Event</a></div>
    <div><a href='#' onclick='addCallbackFromJavascript()'>Add Callback From Javascript</a></div>