How to define a Class in Javascript
First of all, There is no such thing as a Class in Javascript. It’s all objects. Hence use functions and literals to simulate “Class”y development.
//Way 1: Function simulating class.
function Phone(model){
this.model = model;
}
myPhone = new Phone("Android");
//Way 2: literal as singleton
var Phone = {
model: 'Android'
};
//Way 3: Singleton into function
var Phone = new function(){
this.model = "Android"
}
Read Stoyan Stefnov’s article for more.