Based on my observation, the book that I am reading about JavaScript states that there's an OOP with JavaScript? It doesn't tell much about it, I mean it wasn't explained how to define a class. Can someone give me a sample snippet?
Thanks
Based on my observation, the book that I am reading about JavaScript states that there's an OOP with JavaScript? It doesn't tell much about it, I mean it wasn't explained how to define a class. Can someone give me a sample snippet?
Thanks
Here are couple different ways
Another way
Also you could see how jquery, prototype and alike handle classes and see if thats fits you needs.
There is no one standard way of doing OOP in JavaScript. Everyone uses slightly different class/instance systems and most books fudge the issue. See this question for discussion of ways to work with OO in JS and pick your favourite.
I recommend this book for a concise, precise explanation of both how to use JS's prototypal inheritance as well as how to emulate classical OO inheritance in JS.
Any function in javascript can be used to create an object:
Example:
JavaScript is Prototype based and not class based.
The following snippet may help you getting started with JavaScript's class-less, instance-based objects:
Example from: SitePoint - JavaScript Object-Oriented Programming