var Signal = function(a,b,c){return{s:a=[],d:function(){for(c=a.slice();b=c.pop();)b.apply(this,arguments)},r:function(c){a.splice(a.indexOf(b),1)}}} var Something = function(){ this.wasHere = Signal(); this.move = function(){ this.wasHere.d('bigfoot', 'sasquatch'); // d for dispatch! } } // a slot is just a callback ,what = function(wasIt){ // 'this' will be the signal obj itself document.getElementById( "ret" ).innerHTML += 'what it was: ' + wasIt + ' ' + this + '<br />'; } ,scope = (function(wasIt, sas){ // 'this' will be the global obj document.getElementById( "ret" ).innerHTML += 'what it was: ' + wasIt + ' ' + sas + ' ' + this + '<br />'; }).bind(this) var s = new Something(); // unfortunately, these will be executed in reverse order s.wasHere.s.push(what); s.wasHere.s.push(scope); s.move();
<div>Expected value: <b><br />what it was: bigfoot sasquatch [object Window]<br/>what it was bigfoot [object Object]</b></div> <div>Actual value: <br /><b id="ret"></b></div>