javascript - How do I rewrite this to include a debug statement? -
previously had this.
onsuccess: this.receiverequest.bind(this, callback)
this returns function receive requests's bound to supplied bind -- same this
contains receiverequest
method.
so tried rewriting that..
onsuccess : function () { console.log({'xxx: onsuccess': this}); return this.receiverequest.call(this, callback) }.bind(this),
however doesn't work.. why? idea?
when use .bind(this)
on onsuccess
function, it's making context of this
window
or global object - try removing it. should trivial throw debug logic in there, given binding , explicit declaring of context looks may or may not trying achieve more similar this...
// ... receiverequest: function(callback) { console.log('received'); callback(); }, onsuccess: function (cb) { console.log({'xxx: onsuccess': this}); return this.receiverequest.bind(this, cb) } // ... var requestreceivedfunc = myobj.onsuccess(function() { console.log('my callback'); }); requestreceivedfunc();
Comments
Post a Comment