In my react native code, I am using both the bind(this) and var self = this; at multiple places across modules.
Both are solving the problem of resolving this keyword at the right places.
Here are my codes(2 code to perform the same functionality)-
Using
bind(this)retval.then(function (argument) { console.log("argument"+JSON.stringify(argument)); this.stateSetting(argument); }.bind(this));Using
var self = thisvar self = this; retval.then(function (argument) { console.log("argument"+JSON.stringify(argument)); self.stateSetting(argument); });
Considering they both do the same job, I am curious to know what is the right way to do it? Is there an issue in using one or the other? Or is there a better way to do it?
if(self === this)returns true. So, is there a way to destroy self? If it was an object I could have done -self = {}. Should I point self to null in this case? – bozzmob Dec 27 '15 at 19:22retval.then((argument) => { console.log("argument"+JSON.stringify(argument)); this.stateSetting(argument); });developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – lleaff Dec 27 '15 at 19:27