Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Javascript
n00b questions for javascript!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John G Harris, post: 4979977"] You use 'new' to create an object, not a class. This is just as true in Java as in javascript. In general, a class is the collection of all possible objects that have something particular in common. In Java you have class definitions, source text that starts with the keyword 'class', that says what the objects have in common. The definition can also supply additional information such as a name for the class. Javascript is less helpful. You often have to program yourself things that are done by the compiler in other languages. If you want a class definition you have to write it yourself in the form of a constructor function (maybe more than one) and have enough self-discipline to avoid building a horrible mess. If you don't need all the facilities that a constructor function can provide then you may be able to use an object literal instead. In Java, myJar holds a pointer to an area in memory that holds the object's data, etc. 'new' allocates a fresh memory area and arranges for the constructor to act on that area. From then on you can write myJar when you really mean thing-pointed-to-by-myJar. The same is true in javascript. <snip> This doesn't work in Java either. Constructors don't have return type and so can't be used to assign a value to a variable. John [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Javascript
n00b questions for javascript!
Top