, , . , , , .
function test () {
this.that = this;
this.root = this;
this.jCallback = new Array(new Array());
this.jCallbackCount = -1;
this.str = "hello";
this.command = {
that : this,
root : this.root,
add : function(targetFnc, newFunc) {
var that = this;
var home = that.that;
var root = this.root;
home.jCallbackCount++;
home.jCallback[home.jCallback.length] = { 'targetFunc' : targetFnc, 'newFunc' : newFunc, 'active' : true, 'id': home.jCallbackCount};
console.log('cbacklength: ' + home.jCallback.length);
console.log('added callback targetFunction:[' + targetFnc + ']');
return home.jCallbackCount;
},
run : function(targetFnc) {
var that = this;
var home = that.that;
console.log('running callback check for: ' + targetFnc + ' There is : ' + (home.jCallbackCount + 1) + 'in queue.');
console.log('length of callbacks is ' + home.jCallback.length);
for(i=0;i < home.jCallback.length - 1;i++)
{
console.log('checking array for a matching callback [' + targetFnc + ']...');
console.log('current item: ' + home.jCallback[i]['targetFunc'] );
if( home.jCallback[i]['targetFunc'] == targetFnc )
{
home.jCallback[i]['newFunc']();
}
}
}
};
}
test.prototype = {
say : function () {
var that = this;
console.log('inside');
that.command.run('doSay');
console.log(that.str);
}
}
var testing = new test();
testing.command.add('doSay', function () { console.log('213123123'); } );
testing.command.add('doSay', function () { console.log('12sad31'); } );
testing.command.add('doSay', function () { console.log('asdascccc'); } );
testing.say();
:
http://jsfiddle.net/Ps5Uf/