private parameter

If a parameter is declared with keyword private in front of the parameter name, it is a private parameter. A private parameter is accessible but not modifiable outside the function definition body, but can be reset within the function during function execution. For example, in the following function, the private parameter count keeps a record of the times f is called.
>> f = function [private count = 0] x -> y
            this.count = this.count + 1;
            ...
   end
>> f.count
   0
>> f(1);
>> f.count
   1
>> f(2);
>> f.count
   3
>> f.count = 0; // !!! error ...
Inside the function body, to access a private parameter, this keyword must be used. Internal parameters will add to the implicit behavior of a function, and makes the function call results hard to predict, therefore they should be used only when necessary.



oz 2009-12-22