- Home /
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 cannot answer your question about Unityscript/Javascript comparison, but I wanted to be clear on one point. Classes in Unityscript are a blueprint. Object in Unityscript are instances of classes. This is true in C# as well as other program$$anonymous$$g languages. So Unityscript does have objects, but they may not behave like object in Javascript.
Things are a bit more confusing in Unity since classes derived from $$anonymous$$onobehaviour need to be handled differently than standard classes. Classes derived from $$anonymous$$onobehaviour must be attached to a Unity GameObject. Ins$$anonymous$$d of objects, they are referred to as 'components' and the program$$anonymous$$g model as a 'component/object' model. But like objects, you have one class definition and then many possible instances of that class. In Unity you can have classes both classes derived from $$anonymous$$onobehaviour and one not derived from $$anonymous$$onobehavior depending on your need.
If you post a question about what you are trying to do (rather than the differences between the two languages), a large number of users on this list can explain the "Unity way" to accomplish the task.
okay, i just feel like an idiot when i ask questions about things that are obviously not going to work. I would feel stupid if i assumed that the class was going to work the same way as objects and then asked another question.
when you post something on Unity answers (no offense to you, you were very respectful) you often get condescending answers, as if the answer is to say, 'you should have know better in the first place before you came to answers for help.' to save myself from that, i wanted to get a little more information before i posted a question. I suppose i'll just post it anyway, if you think that is best.
you know what, scratch that , from what i read, classes are almost undefinable as a thing. I just don't think i can go that in depth to solve something that i can solve with my good friend the array. I guess i will just do that ins$$anonymous$$d.
Answer by Eric5h5 · Dec 03, 2013 at 10:34 PM
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)
Answer by ffxz7ff · Dec 03, 2013 at 09:46 PM
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.)
I know that UnityScript is different from javascript. i am not a fool who holds onto a silly "belief" that javascript is the same thing as Unities JS.
you need to read some tutorials on object oriented program$$anonymous$$g
from what i understand, Objects (how i know them) do not exist in unity Js or "UnityScript". why should read tutorials on objects?
I made a code that was object oriented i don't need to read some tutorials on it.
You should probably look up how to define a class in Unity's Javascript
maybe so, but before i did so, i wanted to check if classes were what i thought they were in a question. this question is not a pathetic confused shout for help from someone who refuses to believe in the facts when they make things hard for him.
If by "C# libraries" you're talking about .NET functions, those are the same in C# and Unityscript (and Boo), and aren't related to any particular language.
from what i understand, Objects (how i know them) do not exist in unity Js or "UnityScript". why should read tutorials on objects?
Because from what I know, objects as you know them are handled different to objects used in most other program$$anonymous$$g languages, which seems to be the problem that you're running into.
Not understanding classes but clai$$anonymous$$g to know object-oriented program$$anonymous$$g does not compute imo.
Not understanding classes but clai$$anonymous$$g to know object-oriented program$$anonymous$$g does not compute imo.
what, so I'm lying to you now!!
is it possible that you are assu$$anonymous$$g arbitrary facts about a computer language you claim to know nothing about. if you were to know abut JS you would know that there are no classes in it.
this isn't just co$$anonymous$$g from me either
would it shock you to know that I know about object oriented program$$anonymous$$g without knowledge of classes.
maybe you should get your facts straight, ins$$anonymous$$d of accusing me of (what) lying.
there are no classes in JS period.
isn't it likely that someone with only knowledge of JS would not know of classes?
do the math yourself
in fact i would find it surprising if someone with knowledge of only JS did know what classes were
Javascript is a really bizzare language in many ways. It's primarily a functional language, whereas Unityscript and C# are imperative. Javascript borrows the word "Object" to describe what most other languages would simply call a "map" or a "dictionary".
I'd seriously cast aside your javascript experience and learn to use c# with Unity. It's far more explicit (aka less mysterious) and you won't be tempted to equivocate Javascript concepts with Unityscript.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123344im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calling an object from a different JS Script and Instantiate it 1 Answer
Extending a class 1 Answer
array of objects 1 Answer
new Monobehaviour as variable returns warning... 1 Answer
adding classes to arrays 2 Answers