4 ms·
Named parameters would be a good addition, but I wonder how feasible it is to implement. If the signature of the function is known at compile-time it's trivial,
by anonymous 13y ago
Named parameters would be a good addition, but I wonder how feasible it is to implement. If the signature of the function is known at compile-time it's trivial, but what about expressions like `a.b.c.foo(x=2, y=3)`? You'll need some sort of trampoline which takes the function to call, the value of this, a list of the unnamed parameters and a dictionary of the named parameters, then use reflection on the function to call to construct a list of arguments for .apply; and I'm not sure if javascript saves the names of the function's parameters to be available for reflection. Meaning each defined function might have to be an object lugging around some __signature property and named parameters would only work for your own functions.
- byroot 13y ago> I'm not sure if javascript saves the names of the function's parameters to be available for reflection Yes an no. YOu can't access it directly, but if you call toString() on a function you'll get is source code as a string so you can parse it. Prototype do that to handle the special $super parameter [0]. But most modern minifier rename function parameters and local variables, so it's not a good idea. [0] https://github.com/sstephenson/prototype/blob/master/src/prototype/lang/function.js#L38 https://github.com/sstephenson/prototype/blob/master/src/pro...