A while ago I needed to create an object orientated class using jQuery. I turned to use John Resig's fine Class solution.
Hit an issue with it. When I define a global options object, it seems to me that the latter is shared amongst classes. I have confirmed that by printing various console.log's after modifying the object in one class only. The code looks like this:
var MyClass = Class.extend({
defaults : {
distance : 10,
speed : 20
},
options : null,
init : function(options) {
this.options = $.extend(this.defaults, options);
},
...
});
I need a global hash or array so that i can easily pass optional settings to the class. Any way of doing it this way? I might have to resort to manual setters to the class if nothing works.
I am not too sure either why the options object is being statically shared across different class objects instantiated with the 'new' keyword.