Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Parameter number conflict.

That makes sense. With the order reversed, the "$" property ends up being set to a one-parameter delegate. The second call in your script invokes it with two arguments, which is OK, but the first argument is a string that's assumed to be a script function. When the event is raised, an attempt is made to invoke the string, which understandably fails.

The bottom line is that a JavaScript property can't have two values. However, you can create a single delegate that supports both calling patterns:
publicdelegatevoid DollarSignFunc(object arg1, object arg2 = null);
engine.AddHostObject("$", new DollarSignFunc((arg1, arg2) => {
    var name = arg1 asstring;
    if (name == null)
        new Window(f).AddEventHandler("Load", arg1);
    elsenew Window(f).AddEventHandler(name, arg2);
Good luck!

Viewing all articles
Browse latest Browse all 2297