Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to understand some of the differences between writing Object-Oriented Java and Object-Oriented JavaScript. I have a fair amount of experience in Java, but not much experience with Object-Oriented JavaScript. I've tried googling around some, and I keep hearing about how JavaScript is a "Prototypal" language, but I don't quite understand it still. This was probably the most helpful thread about Prototypes: How does JavaScript .prototype work?

I still don't understand exactly what it means for Javascript to be "Prototype Based", though. Some of the more specific questions I have:

  • How does inheritance work in JavaScript?
  • How are private and public fields declared for a JavaScript class?
  • How do declaring static and instance methods differ in JavaScript?

Example code would be very helpful, but what I really need is an explanation of some of the underlying differences between these languages.

share|improve this question

closed as too broad by Philipp, Joe, Ian, Dave Schweisguth, Hovercraft Full Of Eels Jun 11 at 21:36

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You might want to split those up into different questions. There's a lot in here. –  Sotirios Delimanolis Jun 11 at 21:19
    
@SotiriosDelimanolis I'll try to do so as soon as I can, thanks for the tip. –  TheGuyWithTheFace Jun 11 at 21:22
    
It doesn't fully answer your question but... stackoverflow.com/questions/245062/… –  VikingBlooded Jun 11 at 21:23
    
    
2: no private fields, but constructors and methods can have unreachable local and closured variables. Object.defineProperty() provides tools to hide, make "constant", and to create getters and setters. 3. static methods just use the constructor function as an object, for example: window.Object.keys. instance methods in JS can be own (typically defined in-constructor or via extend() ) or inherited via constructor.prototype, which gives all instances past/present/future that property/method (if an own property of the same name is not already defined on a given instance). –  dandavis Jun 11 at 21:39
add comment