cannot use .net exposed functions in a couples of cases

Oct 13, 2011 at 8:56 PM
Edited Oct 13, 2011 at 9:13 PM

I have exposed a C# object with some functions to jint (using SetParamter)

Now I am trying to invoke these via a currying function (dev is the object and installapp is a method on that object)

function curry (fn) {
    var slice = Array.prototype.slice,
        args = slice.apply(arguments, [1]);
    return function () {
       return fn.apply(null, args); <====
    };
}
var x = curry(dev.installapp, "a","b");
x();

this fails saying "The specified 'that' object is not acceptable for this method" pointing at the marked line in the curry function

If I do this instead

function installapp(a,b)
{
    dev.installapp(a,b);
}
function curry (fn) {
    var slice = Array.prototype.slice,
        args = slice.apply(arguments, [1]);
    return function () {
       return fn.apply(null, args);
    };
}
var x = curry(installapp, "a","b");
x();

Then it works. It seems like the functions exposed from .net to JS are almost but not quite fully functional (if you will pardon the pun)

I had the same problem when I tried to pass a .net function exposed to js to another .net exposed function. ie

public int DoIt(Func<int> del)

{

   return del();

}

invoked in js as

var ret = DoIt(dev.getnum);

Fails the same way

 

Just discovered that if I expose the function directly via setfunction then it can be curried directly. THis does mean that I have to expose each function in turn, which is not quite so convenient and I end up with my global namespace full of free floating names

but

var ret = DoIt(function() {return dev.installapp;});

works

In both cases I have to provide a real shallow JS wrapper around the .net function

Oct 13, 2011 at 9:19 PM
Edited Oct 13, 2011 at 9:22 PM

Looks like you trying to invoke an instance method aginst null, this is not very usefull:)

There is an attempt to invoke the CLR method aginst the Global object in the second exmple, which is also illigal.

'installapp' expects a concrete type of an object against which the method should be invoked and neither 'null' nor the Global object is acceptable.

Oct 13, 2011 at 11:53 PM
Edited Oct 14, 2011 at 12:12 AM

oops - i see what you mean