I am developing a programming language which compiles to javascript, the code generated contains too much repetition, like:
cls.$init = function(){
this.property1 = {};
this.anotherProperty = [1, 2, 3, 4];
this.yetAnotherProperty = "test";
/* etc */
}
This could be made much smaller (in that case, when initializing many properties), using a with statement:
cls.$init = function(){
with(this){
property1 = {};
anotherProperty = [1, 2, 3, 4];
yetAnotherProperty = "test";
/* etc */
}
}
But the question is… should I use with statements in generated code? (Which is not meant to be modified later)
The
withstatement is going away in the next ECMAScript standard when using strict mode, so I would get used to not using it.https://developer.mozilla.org/en/JavaScript/Strict_mode#Simplifying_variable_uses