Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables declared with ":" instead of "="

Can someone explain the difference in Javascript between:

var x = something

and

var x : something

I have no idea on where/how to search about it.

I saw the code above at the bottom of page 4 of this document: http://download.unity3d.com/support/Tutorials/2%20-%20Scripting%20Tutorial.pdf

Thanks in advance!

like image 994
Saturnix Avatar asked Nov 01 '12 20:11

Saturnix


2 Answers

The first one assigns something to a variable x and the other causes a syntax error.

You're probably mixing up assigning a property in an object literal and normal assignment.

var x = something;//assigning a variable
var y = {
    x:something//assigning a object property
};

Edit

var target : Transform;

seems to be UnityScript not JavaScript, it looks like it is not assigning a value but rather setting the variable type. see here

like image 99
Musa Avatar answered Nov 08 '22 18:11

Musa


UnityScript is not JavaScript

Unity Script vs Javascript

like image 35
Cory Danielson Avatar answered Nov 08 '22 18:11

Cory Danielson