I found this answer: How to modify "this" in javascript
But I did not like it. Surely there must be a way to somehow modify this?
Actually the problem here is that when you binding the function to a number then the this is getting changed to number and now when you are doing the assignment operation this += 5; the left hand side is not a variable where we can store the new value as its a primitive number instance. so to overcome that what you can do is you can store the this value in another variable say me and then do the operation as following:
(function() {
var a = function(v) {
v += 10;
a = function() {
var me = this;
console.log(this); //logs Number {[[PrimitiveValue]]: 10}
me += 5;
console.log(me); //logs 15
}.bind(v)
//a();
}
a(0);
a();
})();