Javascript class names are implicitly set, but inheritance?

I come from a C/C++ background, and
I’ve read the Unity Scripting Manual.

I was surprised to find that Unity’s JavaScript inheritance
looks surprisingly similar to C++ class inheritance
(well, except for stuff like multiple inheritance
and other details perhaps … but overall, similar idea).
Not coming from a JavaScript background, I had heard
that regular JavaScript’s inheritance was quite convoluted.
(Did I hear the words “prototype inheritance” for regular JavaScript?)

My first question: is Unity’s JavaScript inheritance uniquely
C++ like? Or is regular JavaScript inheritance similar to C++?
I like what I see with Unity’s JavaScript inheritance.
The rumors that I’ve heard about “prototype inheritance” scare me.

My second question is below:

I totally get it when classes explicitly derive from MonoBehavior:

class Foo extends MonoBehaviour
{}

but what about those examples that don’t have a class declaration,
but have a filename like:
Bar.js

// contents of Bar.js:
function Update() {
    transform.Rotate(0, 1, 0);
}

I’ve read that:
“In Javascript, the class name is implicitly set to the file name of
the script (minus the file extension).”
Ok, so that makes sense.

But, what do these “implicit” classes inherit from?
MonoBehaviour?
And are all functions and variables in Bar.js treated as if they were
inside the following class definition?

class Bar extends _____
{
// Are all functions and variables in Bar.js 
// treated as if they belong in here?
}

Thanks,
cmonkey

It’s basically .Net (or rather Mono) inheritance.

Unity Java Script just shares syntax with real Java Script. Underneath it uses the Mono library, which means most functionality from real Java Script doesn’t apply at all. This also makes any documentation about real Java Script pretty much useless. Outside of the Unity manual, the MSDN and/or Mono websites provide the most relevant docs for Unity applications. Although these pages don’t contain examples for Unity’s Java Script, most of the (non-windows specific) support classes will work for Unity JS.

Yes.

Yes.

Thanks tomvds.

Is this the JavaScript implementation that Unity uses?
http://www.mono-project.com/JScript

Is it reasonable to assume that Unity/Mono JavaScript’s
inheritance model is more like C++ than regular JavaScript?
Or are there any tricky surprises that I might run into by
making this assumption? (I’ve heard scary things about
regular JavaScript’s inheritance model.)

Fascinating …

class Bar extends MonoBehaviour
{ 
    // All functions and variables in Bar.js 
    // treated as if they belong in here
    // even though Bar.js has no explicit class declaration!
}

So is this syntactic sugar specific only to Unity’s JavaScript?
Or does non-Unity Mono JScript have similar syntactic sugar?
This is the first time I’ve seen this kind of implicit class
inheritance … but then again, I’ve only used C++/C …
I can certainly see that it can be handy for writing terse code.

Thanks,
cmonkey

No, Unity Java Script exists in Unity only. All this confusion is why you’ll see some of the more stubborn people on this forum (including me :P) refer to it as Unity Script.

Yes. Unity Script has several exclusive features aimed at reducing the amount of typing involved in scripting game objects.

Thanks tomdvs, for all your help
with understanding Unity Script :stuck_out_tongue:

The syntactic sugar for implicit class inheritance
from MonoBehaviour is going to come in handy.

cheers,
cmonkey