Creates an accessor from a getter and a setter.
An accessor is a function that is composed of the getter and the
setter, and which, if called with one more argument than the
number of arguments acceptable by the getter function, calls the
setter function, or otherwise calls the getter function.
A getter must have at least one argument, the object something is
being gotten from. The setter must have at least one more
argument than the getter, which is presumably the value that is
to be set.
The getter and setter the accessor is composed of are available
as the accessor.get and accessor.set properties on the accessor
function. Using the getter and setter directly should only be
done for optimizing accesses when it is really needed.
The getter and setter function must not be wrapped by a function
that doesn't have the proper number of arguments. Fn.partial()
for example returns functions that have a length of 0, and we
conciously reject such functions which reduces the potential of
difficult to find errors.
Parameters:
Name |
Type |
Description |
get |
function
|
|
set |
function
|
|
- Source:
Returns:
-
Type
-
Accessor