C# to Javascript - New Var Conversion

Hello,

I’m trying to convert some C# code into Javascript:

void CreateNewUser(string userName, string password, string email)
	{
		var user = new ParseUser()
		{
		    Username = userName,
		    Password = password,
		    Email = email
		};
		
		user.SignUpAsync();
	}

Its the ‘var user’ thats getting me - mainly because I thought ‘var’ was a Javascript thing, so why is it in C# and working? Anyway, I tried copying it straight and as expected I get errors ’ ; expected’, etc.

What would be the JS conversion be?
Thanks

Var can be used in c#, it’s called type inference. A lot of times in c# you can waste development type explicitly stating the type of a variable.

example:

string myName = "Oliver Jones";

The fact that on the right hand side of the equal sign, you put a string, means it’s a string, so you can infer the type.

var myName = "Oliver Jones";

During the build process it looks at what is being passed into the variable and says “duhh, it’s a string, let it be a string”.

What does the method ParseUser() return, it appears to contstruct a new ParseUser type based off your comments below that is going to the the type you specify in the unityscript/javascript version. So it would look like:

function CreateNewUser(userName:String, password:String, email:String)
    {
       var user:ParseUser = new ParseUser()
       {
           Username = userName,
           Password = password,
           Email = email
       };
 
       user.SignUpAsync();
    }

Hi, I came across the same problem. It doesn’t seem to be an issue with your code, just a bug when using Unity Script + Parse for this particular case. My workaround was to write the signup part in C#. Everything else can stay as JS.