I am trying to grasp the concepts of Javascript through online video courses, where I came upon this example below. https://www.youtube.com/watch?v=9oi0NY8Pen8
The instructor used this example first
var carlike = function(obj, loc) {
obj.loc = loc;
obj.move = function() {
this.loc++;
};
return obj;
};
var amy = carlike({}, 1);
amy.move();
and then changed the carlike function to
var carlike = function(obj, loc) {
obj.loc = loc;
obj.move = function() {
obj.loc++;
};
return obj;
};
Saying the Instead of referring to the parameter this which gets bound to a new value each time move is invoked we can use obj
How is this
getting bound to new value. How can using obj prevent this.