The first one generate a object with static functions but the last generate a function with 2 static functions, is not trully a static class and can be initializated.
In the first case PI is protected by context and in the second case will just not work because PI is a field in the MyMathClass instance and is not a static field.
So i say go with the first if you want a more "trully" static or just put static in PI.
With JSComet you can use static fields/properties and use a @static decorator for make a more trully static class (or create one here some samples github.com/cirospaciari/jscomet.decorators/tree/m…) and private vars and functions are context protecteds.
First Code Generate:
var MyMath;
(function (MyMath) {
var PI = 3.14;
function calculateCircumference(diameter) {
return diameter * PI;
}
MyMath.calculateCircumference = calculateCircumference;
function calculateRectangle(width, length) {
return width * length;
}
MyMath.calculateRectangle = calculateRectangle;
})(MyMath || (MyMath = {}));
Last Code Generate:
var MyMathClass = /** @class */ (function () {
function MyMathClass() {
this.PI = 3.14;
}
MyMathClass.calculateCircumference = function (diameter) {
return diameter * PI;
};
MyMathClass.calculateRectangle = function (width, length) {
return width * length;
};
return MyMathClass;
}());