Jump to content

JavaScript OO Programming


alvo

Recommended Posts

Hi everyone, this has the potential of being a stupid question... so I apologise in advance.. I haven't done a lot of OO programming, I understand objects etc. However I dont quite understand, is a class a set of instructions for an object? and if no, does JavaScript use the prototype option instead of classes? Like a said, might be being a little dumb... can any explain in general how objects, classes, prototypes link together? Not sure if its made matters worse by reading C++ and JavaScript books at the same time? Are they fundamentally the same? Thanks Guys James

Link to comment
Share on other sites

Javascript doesn't have true object-oriented programming. I suggest forgetting about Javascript's odd implementation until you actually are familiar with object-oriented programming in another language. A class is a template for an object that you're going to create. A class (and therefore the objects instantiated from it) contains properties (variables belonging to the class) and methods (functions belonging to the class). Methods can work with other methods and with properties of the class using the "this" keyword. There's more to it, but you'll have to learn it on your own.

Link to comment
Share on other sites

A class is a template for an object that you're going to create. A class (and therefore the objects instantiated from it) contains properties (variables belonging to the class) and methods (functions belonging to the class). Methods can work with other methods and with properties of the class using the "this" keyword. There's more to it, but you'll have to learn it on your own.
Yes, that was my understanding, until I started looking at objects in JavaScript and it threw me right off. Haha, Ok that's fine I understand the theory of it again now thank you. The funny thing is, I know how to create an object is javascript, eg using the new keyword and also the value pairs inside the {} braces, but I just couldn't understand the difference, which made me start to doubt my understanding. Thanks dude*edit* The difference between JS and other languages I mean...
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...