- Home /
Are Unity's JS OOP functions customized?
Hello,
I'm learning implementation of OOP in JS, and seem to be getting conflicting answers from Javascript textbooks and Unity JS tuts.
Case in point:
function smpl_generic (a: float, b: float, c: float)
{
this.a = a;
this.b = b;
this.c = c;
}
...barfs with 'a' not being a member of smpl_generic (filename). Google book link in context.
This, from a WalkerBoy tutorial seems to work, however:
class Test
{
var a;
function Test(aA: float)
{
a = aA;
}
}
To compound my confusion, from what I've been reading is that JS creates classes by itself without announcing them, and that I need to create prototypes for methods. This is NOT from what I've seen being written.
In the link I provided (it's just a single block of text), can someone explain to me what exactly differs in Unity's implementation of JS?
Answer by whydoidoit · Jun 22, 2012 at 10:00 AM
So I'm afraid the first thing to learn is that Unity Script (JavaScript) is not at all like ECMAScript (JavaScript) they share some of the same syntax but Unity Script is a .NET based language built on top of Boo. If you want to learn JavaScript go write some HTML5 for a browser - if you want to learn Unity Script, be aware that there are significant differences to JavaScript and your JavaScript reference books are not going to help much. Buy a Unity programming book or program in C# (which is the same as C# everywhere).
In fact, C# (.Net 2.0) is also EC$$anonymous$$A-compliant. The issue arises because people call UnityScript "JavaScript", which in case is not related to the web version.
I was referring to EC$$anonymous$$AScript rather than any language that is EC$$anonymous$$A compliant. And I believe your second point is the first line of my answer :)
Answer by Eric5h5 · Jun 22, 2012 at 10:09 AM
You'd be better off learning ActionScript 3 if you want to learn Unityscript. It's a lot more similar. Just ignore Javascript, it doesn't really have anything to do with Unity.
Your answer
Follow this Question
Related Questions
Creating a dynamic array of objects of custom class 1 Answer
Error: "ArgumentException: get_deltaTime can only be called from the main thread" 1 Answer
Question about Coroutines in a Class Function 1 Answer
How can I declare class properties of an object in a single line? 2 Answers
Namespace declaration for UnityScript or Unity Javascript 0 Answers