Constant function arguments

David Bruant david.bruant at
Tue Aug 9 08:39:48 PDT 2011


I've been playing around with Rhino recently. It already implements a 
"const" keyword which sounds close to the const proposal (i'm not strong 
on the details of these). If I understand well, Rhino uses "Scriptable" 
objects to store scopes. Constant variables are set as constants in 
these scriptable objects. So, if I understand well, everything can be 
set as constant in a scope... expect function arguments.
Of course, my point here is not to talk about Rhino, but ECMAScript:
Would it make sense to have constant function arguments?

If yes, how should it be declared?

One idea, based on other languages (C, maybe other) could be to do:
function f(const a, b){
   return a+b;

This syntax currently throws a SyntaxError on latest Firefox, Chrome, 
Opera, so i'll assume ES3 and 5.

Regarding rationale and motivation for const arguments, i would give the 
same than for const variables which is to have better expressiveness 
(which allows to catch some errors earlier and to perform easier static 
analysis and optimizations)


More information about the es-discuss mailing list