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

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -