Integrating JavaScript's .bind() with callback function -
so, below barebones example of case i'd set that
this
can use scope of myobj
. how integrate function.prototype.bind, can see how can use in future?
var myobj = { specialfunction: function () { }, anotherspecialfunction(){ }, getasyncdata: function (cb) { // operation cb(); }, render: function () { var = this; this.getasyncdata(function () { that.specialfunction(); that.anotherspecialfunction(); }); } }; myobj.render();
just use bind on method want , specify context
render: function () { this.getasyncdata(this.specialfunction.bind(this)); }
render: function () { this.getasyncdata(somefunction.bind(this)); function somefunction() { this.specialfunction(); this.anotherspecialfunction(); } }
Comments
Post a Comment