Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fospher · Jun 22, 2012 at 09:57 AM · javascriptclassoop

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Jun 22, 2012 at 12:01 PM 0
Share

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.

avatar image whydoidoit · Jun 22, 2012 at 01:45 PM 0
Share

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 :)

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges