Stefan said:
No, that's not possible. array.slice(4,8) will be evaluated first, and
the resulting array will be passed to funcTest.
No, a *reference to* the resulting *Array instance* will be passed to
funcTest().
This is important: Objects do _not_ have names; they have *identity*.
Objects are *never* accessed directly in ECMAScript implementations; they
are *referred to*. The same object can be referred to by *several*
properties of *several other* objects (the base object in that network of
objects, properties and references is the Global Object).
Therefore, if you want to manipulate an Array instance and require
additional arguments, pass the reference to that instance, through a
property name if available (variable identifiers are property names), and
the additional arguments:
function funcTest(objRef, arg1, arg2)
{
return objRef.slice(arg1, arg);
}
console.log(funcTest(a, 4, 8));
Since property names are strings, you can even pass the method name:
function funcTest(objRef, methodName, arg1, arg2)
{
return objRef[methodName](arg1, arg);
}
console.log(funcTest(a, "slice", 4, 8));
Or, even more flexible:
function funcTest(objRef, methodName, args)
{
return objRef[methodName].apply(objRef, [].slice.call(arguments, 2));
}
console.log(funcTest(a, "toString"));
console.log(funcTest(a, "push", 42));
console.log(funcTest(a, "slice", 4, 8));
console.log(funcTest(a, "splice", 4, 1, 42));
// …
(`args' is used here for illustration only; the declaration is not needed.)
PointedEars