dansav
1
How do you do anonymous functions with arguments in unityscript.
I’m trying to translate this from CS.
webViewObject.Init((msg)=>{Debug.Log(string.Format("CallFromJS[{0}]", msg));});
I've tried this
webViewObject.Init=function(msg:String){Debug.Log("CallFromJS["+msg+"]");};
I get
Expression ‘self.webViewObject.Init’ cannot be assigned to.
Eric5h5
2
I guess the type of webViewObject.Init is wrong. This works:
var foo = function(msg:String){Debug.Log("CallFromJS["+msg+"]");};
foo("Yo");
Or if you want to explicitly declare the type:
var foo : function(String) = function(msg:String){Debug.Log("CallFromJS["+msg+"]");};
Did you try this?
webViewObject.Init( function(msg:String) {Debug.Log(“CallFromJS[”+msg+“]”);} );