So what is the deal with this JavaScript i hear people talking about.. Well.. since i am a terrible writer i will with the help of the internet compose my thoughts, not in my own words but in my own way.
I will need to reserve a few posts so i can explain more as i go.. hope that is ok.
If you hang around the JavaScript world long enough you will find standard ways of doing Object Oriented Programming. It looks like this.
And this is how you would do inheritance
So why this? why this mess? and how does it work?
Object Fundamentals
You have a few JavaScript types.
Primitive Types
Special Objects
functions, arrays and regexp are in fact objects.
What are objects?
Object are a set of name / value pairs or key/value pairs
The name can be anything as long as it is a string and each string can be assosiated with any value; Those value can be of any type, meaning any Primitive types or any object type.
Why so special?
Main difference is that Primitives are passed as value, while objects are passed as reference.
Lets look at an example of this.
Lets look at an example of an object.
Remember that i said that objects are stored as references.
One more thing before we are done with the basics.
But the distinction between a deleted value and an actual undefined value is not that important.
Functions & Methods
I told you earlier that a function was an object. When you create it JavaScript creates an object with 3 properties, name, length and prototype
name : "myFunction"
length: 2 //The number of arguments
prototype: ... // I will have to go into detail about this later
Everything you can do with an object you can do to a function.
Method
If you put a function inside of an object, it is called a method; You can run a method like you would run any other function by typing Object.MethodName().
When you do this JavaScript will set the "this" keyword to the object that you have used.
So if you do: myObject.get(), "this" will be set to myObject.
When the method returns, the keyword "this" will be set to whatever value it had before.
The "this" keyword is JavaScripts biggest CATCHA!!!!
It depends in its entirety on the object and not where the function was defined.
Even if you use strict mode you will still need to handle the undefined values, but they are easier to find.
If you want to force a value, you can use call, apply or bind, more on those later.
But as an example we can say
You force the "this" keyword to object1 and when you then call the function val is set to 42.
Now with the basic of objects done, lets get deeper and talk about Prototypal Inheritance.
Prototypal Inheritance
You don't want to define your objects from scratch, that is a maintenance nightmare.
let me give you an example of this nightmare.
This is the status of the code when done incorrectly. You have 3 get keys that points to 1 object (the function)
What would be a better way would to link these together and have them inhere common keys (in this example it is the "get: fn()" that repeats
So what we do to use prototypes is to create a single object and have other inhere from it
to inhere from the parent, or what is also called extend, you use the create method on the child object
You can also add values to the child, or extend it again with another child
Now it gets interesting, we now how a grandchild, child with val: 3.14159 and parent with get: fn(), val: 42
I said earlier that all objects have prototype, even i have not written it, it has this key.
Now let us try to get some values from our new objects.
the object is parent, so this is set to parent, get is inside the parent object so it is run, and it points to a function called fn(). Inside an object this is called a method, so the fn method is run with this as the parent, it will return the value val, which in this case is 42.
this = parent object
get() -> fn() -> returns this.val -> val inside parent = 42
I hope this is clear, if not let me know, this is important to understand how this works.
Let us test how this will work with the child object.
this is set to the child object, it will look for get inside child but will not find it. Then it looks at the prototype, it will go up the prototype chain and look at parent.
Here it finds get, it will then run this.val, and since "this" is set to the child object, it will find it there and return val: 3.14159
this = child object
no get() in child -> prototype -> get() -> fn() -> returns this.val -> val is inside child = 3.14159
Javascript will go as far as it can up the prototype chain to find a property;
So if we said
JavaScript will look for get on the grandchild, then on the child, then on the parent, run the fn() method, "this" is set to grandchild, this.val is not found, it will go up the prototype chain to child and there it fins val: 3.14159
So, this prototype behaviour is how JavaScript works on a fundamental level.
I have no more room, have to use a different post. linke here : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6889
Polymorphism & Method Overriding
Once you have objects in a prototype chain, you might find out you want your children to behave different from their parent even when the same method name is called. This is called Polymorphism (same name but different behavior) and in JavaScript this is quite easy to do. You just use the same property name but assign a different method.
This is just a simple example, but notice that both functions return this.val
Even though it is not a bad example, this is still duplicated logic and in a larger program this kind of code will get quickly difficult to maintain. So typically what we want to do is to call function1 from function2.
But this is not as easy as it might seem, you might want to write it like this.
Before you read on, study the example above and try to see why this is wrong and hence why it returns the wrong answer.
The reason this happens is because when firmAnswer.get() is run, this is set to firmAnswer and it looks for the get property, it finds it and then run fn2(). fn2() in turn runs answer.get() and this is set to answer. It then looks for the get property, finds it and run fn1() and then return this.val. this is set to answer and val in answer = 42
So in order to make this work properly, we need to use the call function.
Take a minute and study this to see if you get why this will work.
When we call firmAnswer.get(), this is set to firmAnswer, it looks for get, finds it and run fn2(), and now it says answer.get.call(this), it sets this to the same as before, firmAnswer and then runs answer.get() right away, and in turn it then runs fn1() and then return this.val. Since this is set to firmAnswer, it will return "3.14159"
I hope this is clear, even though i use a lot of this, i have tried to separate the linguistic meaning of the word and the programming meaning of the word with colors.
Here is the next part : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6923
Classes & Instantiation
You can organize your JavaScript objects in any way you'd like, but a really common way of organizing it is to separate your methods from your data.
Let us organize this code so that we can reuse the function to return different answers.
We will put the function in a prototype and call it AnswerProtype and we will have multiple object extend the prototype to give special values. Let us write the prototype and then some answers to life, universe and everything and let us not forget, pie.
Let us extend this code with the firmAnswer and have it return a lucky number and a magic number.
A prototype (AnswerPrototype and FirmAnswerPrototype) are called Classes and the objects that extends them are called instances (FirmAnswerPrototype would be a subclass by this definition because it extends another class).
Creating a class is called instantiation, and it consist of a two part process, first you create the object by extending the prototype and second you initialize its data.
The problem with the way we have done it in the last example is that we have a lot of duplicated logic, we assign only one value to each object, but in a large program initializing data is a complex process and secondly this way of coding violates encapsulation, one of the biggest corner stones in Object Oriented Programming. To solve this, we will use an initialization function and we will call it constructor.
Note that I have change val to _val, this is a JavaScript coding convention, it means that the property is private and that you should not change it. Nothing in JavaScript is enforcing you to not access or change it, but it is polite not to do anything with it.
This is more or less the complete view of prototypal inheritance and using this model you can do all of your programming :)
The Classical Model
In the last part we instantiated an object by created an object by running a constructor of some sort, that is so common that JavaScript has a special keyword just for that, it is called new
However, new is a little weird, it does not work like the way we have seen up in til now and that is what make the classical model different from the prototypal model.
Before we start i have to show you something strange about functions.
This creates an object with three properties, name, length and prototype.
name = "fn0"
length = 0 // no arguments
prototype = fn0.prototype
the prototype property points to a whole new Object with a constructor property that points back to the function you just created.
This means, whenever you create a function you create two objects, the function object and this prototype object that is just hanging out there.
This is very familiar from what we did before, with Answer() and AnswerPrototype
This means that the extra object is a prototype, basically a class. So every time you define a function in JavaScript you are actually defining a constructor that is associated with a little do nothing class.
Now of course not every function you define is meant to be a constructor, so the common convention in JavaScript is that if it is meant to be a constructor it starts with a capital letter.
If it is meant to be a normal function it starts with a lower case letter.
So, now that the weirdness is over, let us see how this works out by comparing the prototype model with the classical model.
So in simple as i can put it, you use the already created prototype object to construct and initialize the data.
It is a little bit difficult when it comes to sub classes, so let us continue and add the firmAnswer sub class we looked at earlier.
Creating a constructor in FirmAnswer.prototype is not required, but to be consistent we will recreate it.
Here is a side by side comparison of the prototypal and the classical model.
Next part here : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6946
instanceof
It is often a good thing to know which class was used to instantiate an object. Javascript has a keyword instanceof
The way this work is that it looks at a prototype of a constructor and compares it to the object.
There are exceptions to this instanceof rules, it has to do with how certain objects will traverse up the prototype chain, but i don't want to make it more confusing by writing myself in a corner.
This is everything you need to know to understand how Inheritance work in JavaScript
There is some changes in the newest version of Ecma Script 6, one is that you can use class definition like other object oriented languages uses.
Study this at your own leisure.
This is it for now, there are a lot more, but this is the basis of Object Oriented JavaScript. There are plenty more to cover, getter and setters, static variables, how bind and apply works, but this is the start.
I use the classical model, works well in my IDE and support instanceof, i also "use strict"; mode, since i always want to have this be defined.
http://jshint.com/
http://www.jslint.com/
Two websites i recommend, bookmark them ;)
I am also try to go over to the ES6 class syntax, but until browser fully support it i am reluctant (ES6 in whole)
Hope this will be useful to someone ;)
I will need to reserve a few posts so i can explain more as i go.. hope that is ok.
If you hang around the JavaScript world long enough you will find standard ways of doing Object Oriented Programming. It looks like this.
JavaScript:
function MyClass() {
...
}
MyClass.prototype.method = function() {
...
}
JavaScript:
function MySubClass() {
MyClass.call(this);
...
}
MySubClass.prototype = Object.create(MyClass.prototype);
MySubClass.prototype.constructor = MySubClass;
MySubClass.prototype.method = function() {
MyClass.prototype.method.call(this);
...
}
Object Fundamentals
You have a few JavaScript types.
Primitive Types
Code:
Undefined: undefined
Null: null
Boolean: true
String: "foo"
Number: 3.14159
Object: { bar: "baz" }
Code:
Function: function qwe() {...}
Array: [ "answer", 42]
RegExp: /piyo/
What are objects?
Object are a set of name / value pairs or key/value pairs
The name can be anything as long as it is a string and each string can be assosiated with any value; Those value can be of any type, meaning any Primitive types or any object type.
Why so special?
Main difference is that Primitives are passed as value, while objects are passed as reference.
Lets look at an example of this.
JavaScript:
var number1, number2;
number1 = 3.14159;
number2 = number1; // => numer2 is now 3.14159
number2 = 42; // => number2 is now 42, number 1 is unchanged
Remember that i said that objects are stored as references.
JavaScript:
var object1, object2
object1 = {
a: 3.14159
};
object2 = object1; // => object2s value is now 3.14159
object2.a = 42; // => now both objects have the same value
JavaScript:
var myObject = {
a: "foo",
b: "bar",
c: "baz"
};
myObject.x; // => undefined
myObject.c = undefined;
// the value c does not get removed just because you set its value to undefined, you will have to use the delete command.
delete myObject.c;
Functions & Methods
I told you earlier that a function was an object. When you create it JavaScript creates an object with 3 properties, name, length and prototype
JavaScript:
function myFunction(a,b) {
return 42;
};
length: 2 //The number of arguments
prototype: ... // I will have to go into detail about this later
Everything you can do with an object you can do to a function.
- Assign properties
- Assign them to different variables
JavaScript:
function myFunction(a,b) {
return 42;
};
myFunction.foo = "bar";
var function2 = myFunction;
function2(); //=> 42
If you put a function inside of an object, it is called a method; You can run a method like you would run any other function by typing Object.MethodName().
When you do this JavaScript will set the "this" keyword to the object that you have used.
So if you do: myObject.get(), "this" will be set to myObject.
JavaScript:
var myObject = {
get: function myMethod() {
return this.val;
},
val: 42
};
myObject.get(); //=> 42
The "this" keyword is JavaScripts biggest CATCHA!!!!
It depends in its entirety on the object and not where the function was defined.
JavaScript:
function myMethod() {
return this.val;
}
var object1 = {
get: myMethod,
val: 42
};
var object2 = {
get: myMethod,
val: 3.14159
};
object1.get(); //=> 42
object2.get(); //=> 3.14159
myMethod(); // ???? you will never know for sure what it will return, if you use strict mode this will be undefined.
If you want to force a value, you can use call, apply or bind, more on those later.
But as an example we can say
JavaScript:
myMethod.call(object1); //=> 42
Now with the basic of objects done, lets get deeper and talk about Prototypal Inheritance.
Prototypal Inheritance
You don't want to define your objects from scratch, that is a maintenance nightmare.
let me give you an example of this nightmare.
JavaScript:
//This is not correct
function fn() {
return this.val;
}
var object1 = {
get: fn,
val: 42
};
var object2 = {
get: fn,
val: 3.14159
};
var object3 = {
get: fn,
val: 84
};
Code:
// fn() //
name: "fn"
length: 0
prototype: ...
////////////
// object1 //
get: fn()
val: 42
////////////
// object2 //
get: fn()
val: 3.14159
////////////
// object3 //
get: fn()
val: 84
////////////
What would be a better way would to link these together and have them inhere common keys (in this example it is the "get: fn()" that repeats
So what we do to use prototypes is to create a single object and have other inhere from it
JavaScript:
var parent = {
get: function fn() {
return this.val;
},
val: 42
};
You can also add values to the child, or extend it again with another child
JavaScript:
var child = Object.create(parent);
child.val = 3.14159;
var grandchild = Object.create(child);
Code:
//parent//
get: fn()
val:42
----------
//child//
val:3.14159
-----------
//grandchild
-----------
Now let us try to get some values from our new objects.
JavaScript:
parent.get(); // => 42
this = parent object
get() -> fn() -> returns this.val -> val inside parent = 42
I hope this is clear, if not let me know, this is important to understand how this works.
Let us test how this will work with the child object.
JavaScript:
child.get(); //=> 3.14159
Here it finds get, it will then run this.val, and since "this" is set to the child object, it will find it there and return val: 3.14159
this = child object
no get() in child -> prototype -> get() -> fn() -> returns this.val -> val is inside child = 3.14159
Javascript will go as far as it can up the prototype chain to find a property;
So if we said
JavaScript:
grandchild.get(); //=> 3.14159
JavaScript:
var parent = {
get: function fn() {
return this.val;
},
val: 42
};
var child = Object.create(parent);
child.val = 3.14159;
var grandchild = Object.create(child);
parent.get(); // => 42
child.get(); //=> 3.14159
grandchild.get(); //=> 3.14159
I have no more room, have to use a different post. linke here : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6889
Polymorphism & Method Overriding
Once you have objects in a prototype chain, you might find out you want your children to behave different from their parent even when the same method name is called. This is called Polymorphism (same name but different behavior) and in JavaScript this is quite easy to do. You just use the same property name but assign a different method.
JavaScript:
var answer = {
get: function fn1() {
return this.val;
},
val: 42
};
var firmAnswer = Object.create(answer);
firmAnswer.get = function fn2() {
return this.val + "!!";
};
answer.get(); //=> 42
firmAnswer.get(); //=> "42!!"
This is just a simple example, but notice that both functions return this.val
Even though it is not a bad example, this is still duplicated logic and in a larger program this kind of code will get quickly difficult to maintain. So typically what we want to do is to call function1 from function2.
But this is not as easy as it might seem, you might want to write it like this.
JavaScript:
//This code is NOT CORRECT
//The part "return answer.get()" is wrong
var answer = {
get: function fn1() {
return this.val;
},
val: 42
};
var firmAnswer = Object.create(answer);
firmAnswer.get = function fn2() {
return answer.get() + "!!";
};
firmAnswer.val = 3.14159;
firmAnswer.get(); //=> "42!!" (what we want to have returned is [COLOR=#ff8000]3.14159!![/COLOR])
The reason this happens is because when firmAnswer.get() is run, this is set to firmAnswer and it looks for the get property, it finds it and then run fn2(). fn2() in turn runs answer.get() and this is set to answer. It then looks for the get property, finds it and run fn1() and then return this.val. this is set to answer and val in answer = 42
So in order to make this work properly, we need to use the call function.
JavaScript:
var answer = {
get: function fn1() {
return this.val;
},
val: 42
};
var firmAnswer = Object.create(answer);
firmAnswer.get = function fn2() {
return answer.get.call(this) + "!!";
};
firmAnswer.val = 3.14159;
firmAnswer.get() //=> "3.14159!!"
When we call firmAnswer.get(), this is set to firmAnswer, it looks for get, finds it and run fn2(), and now it says answer.get.call(this), it sets this to the same as before, firmAnswer and then runs answer.get() right away, and in turn it then runs fn1() and then return this.val. Since this is set to firmAnswer, it will return "3.14159"
I hope this is clear, even though i use a lot of this, i have tried to separate the linguistic meaning of the word and the programming meaning of the word with colors.
Here is the next part : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6923
Classes & Instantiation
You can organize your JavaScript objects in any way you'd like, but a really common way of organizing it is to separate your methods from your data.
JavaScript:
var answer = {
get: function fn1() {
return this.val;
},
val: 42
};
answer.get(); //=> 42
We will put the function in a prototype and call it AnswerProtype and we will have multiple object extend the prototype to give special values. Let us write the prototype and then some answers to life, universe and everything and let us not forget, pie.
JavaScript:
var AnswerPrototype = {
get: function fn1() {
return this.val;
}
};
var lifeAnswer = Object.create(AnswerPrototype);
lifeAnswer.val = 42
lifeAnswer.get(); //=> 42
var desertAnswer = Object.create(AnswerPrototype);
desertAnswer.val = 3.14159
desertAnswer.get(); //=> 3.14159
JavaScript:
var AnswerPrototype = {
get: function fn1() {
return this.val;
}
};
var lifeAnswer = Object.create(AnswerPrototype);
lifeAnswer.val = 42
lifeAnswer.get(); //=> 42
var desertAnswer = Object.create(AnswerPrototype);
desertAnswer.val = 3.14159
desertAnswer.get(); //=> 3.14159
var FirmAnswerPrototype = Object.create(AnswerPrototype);
FirmAnswerPrototype.get = function fn2() {
return AnswerPrototype.get.call(this) + "!!";
};
var luckyAnswer = Object.create(FirmAnswerPrototype):
luckyAnswer.val = 7;
luckyAnswer.get(); //=> "7!!"
var magicAnswer = Object.create(FirmAnswerPrototype);
magicAnswer.val = 3;
magicAnswer.get(); //=> "3!!"
Creating a class is called instantiation, and it consist of a two part process, first you create the object by extending the prototype and second you initialize its data.
The problem with the way we have done it in the last example is that we have a lot of duplicated logic, we assign only one value to each object, but in a large program initializing data is a complex process and secondly this way of coding violates encapsulation, one of the biggest corner stones in Object Oriented Programming. To solve this, we will use an initialization function and we will call it constructor.
JavaScript:
var AnswerPrototype = {
constructor: function fn0(value) {
this._val = value;
},
get: function fn1() {
return this._val;
}
};
var lifeAnswer = Object.create(AnswerPrototype);
lifeAnswer.constructor(42);
lifeAnswer.get(); //=> 42
var desertAnswer = Object.create(AnswerPrototype);
desertAnswer.constructor(3.14159);
desertAnswer.get(); //=> 3.14159
var FirmAnswerPrototype = Object.create(AnswerPrototype);
FirmAnswerPrototype.get = function fn2() {
return AnswerPrototype.get.call(this) + "!!";
};
var luckyAnswer = Object.create(FirmAnswerPrototype):
luckyAnswer.constructor(7);
luckyAnswer.get(); //=> "7!!"
var magicAnswer = Object.create(FirmAnswerPrototype);
magicAnswer.constructor(3);
magicAnswer.get(); //=> "3!!"
This is more or less the complete view of prototypal inheritance and using this model you can do all of your programming :)
The Classical Model
In the last part we instantiated an object by created an object by running a constructor of some sort, that is so common that JavaScript has a special keyword just for that, it is called new
However, new is a little weird, it does not work like the way we have seen up in til now and that is what make the classical model different from the prototypal model.
Before we start i have to show you something strange about functions.
JavaScript:
function fn0() {
};
name = "fn0"
length = 0 // no arguments
prototype = fn0.prototype
the prototype property points to a whole new Object with a constructor property that points back to the function you just created.
This means, whenever you create a function you create two objects, the function object and this prototype object that is just hanging out there.
This is very familiar from what we did before, with Answer() and AnswerPrototype
JavaScript:
function Answer() {
};
var AnswerPrototype = {
constructor: function fn0() {
this._val = 42;
}
};
Now of course not every function you define is meant to be a constructor, so the common convention in JavaScript is that if it is meant to be a constructor it starts with a capital letter.
If it is meant to be a normal function it starts with a lower case letter.
So, now that the weirdness is over, let us see how this works out by comparing the prototype model with the classical model.
JavaScript:
//Prototype model
var AnswerPrototype = {
constructor: function fn0(value) {
this._val = value;
},
get: function fn1() {
return this._val;
}
};
var lifeAnswer = Object.create(AnswerPrototype);
lifeAnswer.constructor(42);
lifeAnswer.get(); //=> 42
var desertAnswer = Object.create(AnswerPrototype);
desertAnswer.constructor(3.14159);
desertAnswer.get(); //=> 3.14159
JavaScript:
// Classical model
function Answer(value) {
this._val = value;
}
Answer.prototype.get = function fn1() {
return this._val;
};
var lifeAnswer = new Answer(42);
lifeAnswer.get(); //=> 42
var desertAnswer = new Answer(3.14159);
desertAnswer.get(); //=> 3.14159
It is a little bit difficult when it comes to sub classes, so let us continue and add the firmAnswer sub class we looked at earlier.
JavaScript:
function Answer(value) {
this._val = value;
}
Answer.prototype.get = function fn1() {
return this._val;
};
var lifeAnswer = new Answer(42);
lifeAnswer.get(); //=> 42
var desertAnswer = new Answer(3.14159);
desertAnswer.get(); //=> 3.14159
// This is where we left off in the previous example
function FirmAnswer(value) {
Answer.call(this, value);
} // JavaScript will now create a new protoype object, but we need to extend a different class, so we can not use this prototype as a constructor, we will instead make a new prototype object and point it to the Answer.prototype object, the extra unused object will be collected by the garbage collector since nothing is now pointing at it
FirmAnswer.prototype = Object.create(Answer.prototype);
FirmAnswer.prototype.constructor = FirmAnswer; //Since the other object with the original constructor has been removed by the garbage collector, we need to make a new constructor property and point it back to FirmAnswer.
FirmAnswer.prototype.get = function fn2() {
return Answer.prototype.get.call(this) + "!!";
};
var luckyAnswer = new FirmAnswer(7);
luckyAnswer.get(); //=> "7!!"
var magicAnswer = new FirmAnswer(3);
magicAnswer.get(); //=> "3!!"
Here is a side by side comparison of the prototypal and the classical model.

Next part here : http://www.rpgmakermv.co/threads/javascript-201.616/#post-6946
instanceof
It is often a good thing to know which class was used to instantiate an object. Javascript has a keyword instanceof
The way this work is that it looks at a prototype of a constructor and compares it to the object.
JavaScript:
function Answer(value) {
this._val = value;
}
Answer.prototype.get = function fn1() {
return this._val;
};
function FirmAnswer(value) {
Answer.call(this, value);
}
FirmAnswer.prototype = Object.create(Answer.prototype);
FirmAnswer.prototype.constructor = FirmAnswer;
FirmAnswer.prototype.get = function fn2 () {
return Answer.prototype.get.call(this) + "!!";
};
var lifeAnswer = new Answer(42);
var luckyAnswer = new FirmAnswer(7);
lifeAnswer instanceof Answer; //=> true
// First it looks at Answer prototype (this is the Answer.prototype object)
//Then it looks at the lifeAnswer prototype (this is the Answer.prototype object)
// since this is the same object, it returns true
lifeAnswer instanceof FirmAnswer; //=> false
// First it looks at FirmAnswer prototype (this is the FirmAnswer.prototype object)
//Then it looks at the lifeAnswer prototype (this is the Answer.prototype object)[/SIZE]
// since this is not the same object, it returns false
This is everything you need to know to understand how Inheritance work in JavaScript
There is some changes in the newest version of Ecma Script 6, one is that you can use class definition like other object oriented languages uses.
JavaScript:
class Answer {
constructor(value) {
this._val = value;
}
get() {
return this._val;
}
}
var lifeAnswer = new Answer(42);
lifeAnswer.get(); //=> 42
var dessertAnswer = new Answer(3.14159);
dessertAnswer.get(); //=> 3.14159
class FirmAnswer extends Answer {
constructor(value) {
super(value);
}
get() {
return super() + "!!";
}
};
var luckyAnswer = new FirmAnswer(7);
luckyAnswer.get(); //=> "7!!"
var magicAnswer = new FirmAnswer(3);
magicAnswer.get(); //=> "3!!"
This is it for now, there are a lot more, but this is the basis of Object Oriented JavaScript. There are plenty more to cover, getter and setters, static variables, how bind and apply works, but this is the start.
I use the classical model, works well in my IDE and support instanceof, i also "use strict"; mode, since i always want to have this be defined.
http://jshint.com/
http://www.jslint.com/
Two websites i recommend, bookmark them ;)
I am also try to go over to the ES6 class syntax, but until browser fully support it i am reluctant (ES6 in whole)
Hope this will be useful to someone ;)
Last edited by a moderator: