I was reading an article on Unity JS. The article showed an example of a class in unity js.
class Person{
var name;
var career;
}
//Create objects of type Person
var john = Person();
john.name = "John Smith";
john.career = "doctor";
Debug.Log(john.name + " is a " + john.career);
It looks like Unity JS actually supports the class
keyword. How does it support class
with JavaScript? Are they using dead ES4 spec or a modified ES3 or 5?
Classes are the blueprints for your objects. Basically, in Unity, all of your scripts will begin with a class declaration. Unity automatically puts this in the script for you when you create a new C# script. This class shares the name as the script file that it is in.
It's a proprietary language and it doesn't actually follow any concrete specification of standard JavaScript and is modified at will by the engine developers. > Because of this, the vast majority of JavaScript libraries you find will not work by default in Unity.
Also, that Javascript is no longer supported on Unity3d.
Go with c#, unityscript is slooooooooowwwwwwlllyyyy going the way of the dodo. All the newer unity framework documentation and tutorials is in c#, better overall support from msdn and core library docs, better library support. Used outside of unity etc.
Check out this article on the differences between UnityScript and JavaScript: http://wiki.unity3d.com/index.php?title=UnityScript_versus_JavaScript
In addition: Wikipedia describes UnityScript as "a custom language with ECMAScript-inspired syntax"
Unity's Javascript is not real Javascript, it's a new language for beginners with similar syntax. Some people prefer to call it UnityScript because they're just two different languages.
Unity's Javascript is a class-based OO language which supports all OOP features, and it can be compiled to the same assembly code just as C# in Unity.
for example, a javascript file "Foo.js" in Unity
var myVar : int;
function Update() {}
is identical to a C# script like
class Foo : MonoBehaviour {
int myVar;
void Update() {}
}
I mean 100% identical even though you can't find the keyword 'class' in Foo.js, but you are actually creating a Foo object.
you can inherit class Foo in another script "Boo.js" to verify what I say:
class Boo extends Foo {
function Update() {}
}
Unity's javascript has javscript's syntax, but C#'s spirit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With