Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Feature: Support for specifying host method arguments by name [80]

0
0
Neither JavaScript nor VBScript have native support for named arguments, but some way to specify host method arguments by name might be useful.
Comments: Hi Ram, ​ >Object literal syntax should be a nice alternative. I don't know what host.args would return to make Console.WriteLine work. ​ It would return an object that could be recognized as a set of named arguments rather than an arbitrary script object or managed dictionary. Such an object would probably be an instance of a specific internal type that's reserved for this purpose. ​ >Just to avoid host.args from being part of every line of the script can the engine somehow detect that Console.WriteLine (or any other such exposed method) expects multiple (or non-object) parameters but is being passed an object and accordingly do whatever host.args plans to do? ​ ClearScript uses C#-style method binding, where the arguments play a critical role, whether they're selecting a method overload, specializing a generic method, or both. The problem is that an arbitrary script object is ambiguous; it could be interpreted as a single argument or a set of named arguments, and the intended method could be declared or overloaded such that both interpretations are viable. The killer is that this ambiguity could be intractable. For example, it could come into play only when the object's property names happen to match the method's parameter names, something the script writer may not be able to predict. The bottom line is that this approach, while yielding convenient syntax, would probably be too unsafe to merit recommendation. It would also greatly complicate method binding, which is already expensive. Consider also that you could alias "host.args" down to a single character: ``` JavaScript // JavaScript $ = host.args; myObject.DoSomething($({ a: 123, b: 456 })); ``` Opinions?

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images