Reading some legacy code, and found
A.prototype.setSize: function () {
var v1 = new Vector2();
return function (size ) {
var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
this.min.sub( halfSize );
return this;
};
}(),
I am wondering:
- why define setSize as a function which return another function
- Also the defined function is executed right away.
any light to shed on this?
Updated:
I can simply use
A.prototype.setSize: function (size) {
var v1 = new Vector2();
var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
this.min.sub( halfSize );
return this;
},
Is the first snippet better than second?