I probably doesn't help I'm mentally deficient after a work day so maybe I should sit down on my day off, but I look at the code for the base classes and I just don't 'get it'.
I think I'm so used to other languages, having defined variables, classes and functions that looking at Javascripts more dynamic typing confuses me when things get more complicated then simple examples.
Like why do you set Game_Actor.prototype to Object.create(Game_Battler.prototype)? my understanding of prototype is that it is similar to a class in other languages, parent class. Why would you want Game_Actor have it's parent be the parent of Game_Battler, instead of Game_Battler?
No, it's not.
You should think at a function more as the constructor of your instance,
also every function has a prototype object that your instance will magically refer to in order to resolve your method call
Let' s look at the classical JavaScript way to extend a "Class":
function A(){}A.prototype.foo = function(){console.log('foo')}function B(){}B.prototype = new A()B.prototype.bar = function(){console.log('bar')}var a = new A()var b = new B()a.foo() //foob.foo() //foob.bar() //barconsole.log(a.bar) //undefinedconsole.log(a instanceof A) //true
console.log(a instanceof B )//false
console.log(b instanceof A) //true
console.log(b instanceof B ) //true
As you can see here b inherits both A and B's prototypes methods
the problem here is that in order to keep B an instance of A you have to actually make B.prototype an instanceof A using new and this runs the function,
this works in this example as the A constructor function takes no parameter and do nothing, but there are cases where you don't know the correct number of parameter
or you just don't want to run the constructor because you want to do that later,
http://www.3site.eu/doc/ explains this problem very well and basically shows the solution of using an intermediate parameterless function which shares the same prototype of A so that you can later changes B.prototype without reflecting the changes in A.prototype.
This pattern was so common that we now have Object.create that basically does just like that,
Object.create when called with just one parameter can be summarized as:
Object.create = function (proto) { function Intermediate(){} Intermediate.prototype = proto return new Intermediate()}So, no, prototype is not similar to a class, it's is own thing, I can also suggest, apart for Andrea article I linked before to read
http://dmitrysoshnikov.com/ecmascript/javascript-the-core/#constructor if you want to understand the basic inner working of JS