Below you will find two different decorator patterns. One uses "this" while the other one defines the object in the function arguments.
What is the advantage of defining the object vs using "this" from a memory/performance perspective? When is it appropriate to use this rather then defining the object?
//Using this in the object
var carlike = function(loc) {
this.loc = loc;
var move = function() {
this.loc++;
};
this.move = move;
return this;
};
//Defining the object in the arguments
var carlike = function(obj, loc) {
obj.loc = loc;
var move = function(obj) {
obj.loc++;
};
obj.move = move;
return obj;
};