Why can Object.gameObject convert from Object to GameOjbect?

Hello guys! Now I am using Java Script. When I want to destroy a "Object" created by "Instantiant" command. I just use Ojbect.gameOjbect, and it works. But I am so confused about this. As we all know, GameObject inherts form Object, why Object.gameObject can convert father class to child class? Is there any tricks in JS to do that? Thanks for any information!

There is no such thing as Object.gameObject. UnityScript converts the Object to a Component first behind the scenes.

http://unity3d.com/support/documentation/ScriptReference/Component-gameObject.html

You basically already answered your own question: GameObject is a subclass of Object, and when you have a variable of type Object that carries a GameObject (which it can due to the inheritance structure), you can easily cast that back to being an "official GameObject".

However, there is no Object.gameObject (see also class Object). What you are probably referring to is Component.gameObject - and that is, as it name implies, already of type GameObject. So, in that case, there's not even a cast taking place.

Hm ... I'm adding a comment to clarify something ;-)