3 ms·
Not cleanly. You have to pass the arguments in explicitly, and you also need to convert them to an array (the arguments object is not an array [only array-like]
by curveship 13y ago
Not cleanly. You have to pass the arguments in explicitly, and you also need to convert them to an array (the arguments object is not an array [only array-like] and it's not supposed to escape its function body). So you need to do:
var args = Args([
... defs ...
], Array.prototype.slice.call(arguments));
- adam-a 13y agoI have just updated the code to remove the Function.caller.arguments part, this means you have to pass through the arguments variable manually. The arguments object is not a real array, this is true, but it has a length and is indexable, so Args.js still works ok. I have seen on MDN[0]: > The arguments object is available only within a function body. Attempting to access the arguments object outside a function declaration results in an error. It doesn't actually cause an error though, so am I misreading that? Besides, by that definition passing arguments to Array.prototype.slice.call() is also a no-no. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- curveship 13y agoThe ES5 spec specifically allows (but doesn't require) implementations to create an Array.prototype.slice that accepts 'arguments': > NOTE: The slice function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the slice function can be applied successfully to a host object [ed: 'arguments' is one such] is implementation-dependent. [0] 'arguments' isn't just array-like. It's got some very weird behavior. For instance, if your function also has named parameters, and you set an index on the arguments object that corresponds with a parameter, then it changes the value of the local parameter as well. 0 - http://es5.github.io/#x15.4.4.10 http://es5.github.io/#x15.4.4.10