how to call js class's method?

Jun 30, 2014 at 12:46 PM
hi,I want to use this for unity and jurassic

such like :

cs:
void Awake(){
    engine.call(jsfile:   Awake())
}

vod Start(){
engine.call(jsfile: Start()) 
}
and my js file may be look like
(function () { "use strict";
var Main = function() { };
Main.main = function() {
    new Test();
};
var Test = function() {
};
Test.prototype = {
    Awake: function() {
    }
    ,Start: function() {
    }
};
Main.main();
})();
and I want to ask Can I call js Class function from c#? any help?
Jul 2, 2014 at 9:52 AM
finaly,I know how to do this
engine.Execute(value);

engine.CallGlobalFunction("Awake");//ect

BTW,I have another question about my js file
it's was create by Haxe,
such like

how to invoke Main.main() this style function ,
and I got some error,
InvalidOperationException: 'Main.Start' is not a function.

here is my code
(function () { "use strict";
var Main = function() { };
Main.main = function() {
    Main.Start();
};
Main.Start = function() {
    var g = new GameObject();
    g.transform.localPosition = new Vector3(1,2,3);
    
};
})();
Coordinator
Jul 2, 2014 at 11:15 PM
You've wrapped Main within a function so Main is a local variable and thus not accessible from C# code.

This will work I think:
"use strict";
var Main = function() { };
Main.main = function() {
    Main.Start();
};
Main.Start = function() {
    var g = new GameObject();
    g.transform.localPosition = new Vector3(1,2,3);
    
};
Jul 3, 2014 at 1:49 AM
Edited Jul 3, 2014 at 1:53 AM
sorry ,I mean how to call js function like this.
 engine.CallGlobalFunction("Main.Start"); 
and I still got
InvalidOperationException: 'Main.Start' is not a function.
it's possible?
Coordinator
Jul 3, 2014 at 5:48 AM
Try this:
engine.Execute("Main.Start()");
Jul 3, 2014 at 8:08 AM
Edited Jul 3, 2014 at 8:16 AM
it's work!