For immutable structures I believe you're looking for Immutable.js.
As @Andreas_Gnyp is saying, until ES6 there is no let
/ const
in JavaScript. (Nor there will be function(const a) {...}
once ES6 is out and fully supported.) If you want to use const
, you can either implement your own const
feature, or start using ES6 notation with help of some third party ES6-to-ES5 compiler, such as Babel.
However, bear in mind that const
in ES6 notation does not make the variable immutable. E.g. const a = [1, 2]; a.push(3);
is a completely valid program and a
will become [1, 2, 3]
. const
will only prevent you from reassigning a
, so that you can't do a = []
or a = {}
or whatever once const a = [1, 2];
already defined (in that particular scope).
function hasConstantParameters(...args) {
const [a, b] = args;
}
Immutable.js will make sure that, when you define var a = fromJS([1, 2]);
and pass a
as a function parameter, in the receiving function a.push(3)
will not affect a
. Is this what you wanted to achieve?