JS Objects VS Class (are they the same?????)

first off, if you aren’t familiar with JS (Not the Unity JS, traditional web JS) objects you probably won’t be able to help me.

In JS (non Unity) there things known as objects. in a previous question i asked about JS Objects and found that you cannot really create an object in Unity Script. The person who answered the question i asked told me something about classes, they made it seem as though i could use them in the same way (relatively).

eager to continue working on my project, i assigned a variable to a class and treated it exactly like a JS Object.

I am encountering some problems i cannot explain.

My only conclusion to draw is that classes and JS Objects are not the same thing.

I need to know their differences, so i know where to use something else instead. Been considering just switching over to multidimensional arrays for this project for a while now. but i would rather completely change my object oriented code if I don’t have to.

thanks for taking time to read this.

Have a Quishtay™ day!!

I think what’s confusing you the most is the belief that Unity’s JavaScript is like the JavaScript used in web-programming. But it’s so different that some people call it UnityScript instead. Also you need to read some tutorials about object-oriented programming.

eager to continue working on my project, i assigned a variable to a class and treated it exactly like a JS Object.

Did you do it like in your previous question? You should probably look up how to define a class in Unity’s JavaScript. Or in C#. Or in Java. That will help you understand.

My only conclusion to draw is that classes and JS Objects are not the same thing.

Spoken very simplified, the class is a cake tin, the object is any cake that you make using that tin.

Don’t expect JavaScript. UnityScript is, from what I know, rather similar to C# with a slightly different syntax. (I hope this last information was right, disclaimer: I don’t use UnityScript myself because the C# libraries offer more functionality.)

Objects in Javascript are similar to classes in Unityscript, but they’re not the same. Take a look at this page, which details the differences between JScript 5.5 and JScript.NET, which is extremely similar to the differences between Javascript and Unityscript. Specifically, the comparison about halfway down the page between a Car object in JScript 5.5 and a Car class in JScript.NET is essentially identical to the difference between a Javascript object and a Unityscript class.

The Car class would compile in Unity, although the class constructor should be changed from

function Car(make, color, year)

to

function Car(make : String, color : String, year : int)