Ok so here's a bit of code that i am working with atm.
My Problem is that I don't really get the difference between an object and an object prototype. Up until now I thought, if I make a new Object, e.g. new Memory, this inherits all the properties I declared in Memory. In my code, however, i need to add options to Memory.prototype.
So my core question is: What is the difference between properties of the object and properties of the object.prototype?
Edit: to specify: in the Memory function I log this.options. This doesn't work, unless I include Memory.prototype.options = {...}. If a new Memory inherits the properties from Memory and I defined e.g this.options.availableCards just above, why do I need to add options to the prototype?
var createMemory = function (){
new Memory( {wrapperID: 'memory-game'} );
};
var Memory = function (options) {
//check for required options
if ((options.wrapperID === undefined)){
console.error('ERROR: not all required options given. wrapperID is required!');
return false;
}
//hardcoded values
this.options.availableCards = 22;
this.options.cols = 4;
this.options.rows = 4;
this.options.fliptime = this.options.flipTime || 1; //set default
this.options = extend({}, this.options);
extend(this.options, options);
//this._init();
console.log(this.options);
};
// why is this required?
Memory.prototype.options = {
onGameEnd: function(){
return false;
}
};
createMemory();