Defining Vector any other way would create it only within the scope of closure; and will not be available outside of closure.
(function() { var Vector = function(x, y) { this.x = x; this.y = y; return this; }; function Vector() {
Nothing requires the var keyword; using it, defines the scope in which the variable is available. Without using it, the variable is created in the global scope.
source share