jQuery does not define OOP primitives, so you are on your own. But it's easy to do what you want using regular JavaScript:
MyClass = function(options){
And you can create instances that you used to:
var mc = new MyClass({});
If you used more things in the prototype, you can add them as you used to:
MyClass.prototype = { // no need for initialize here anymore /* initialize: function(options) { }, */ // the rest of your methods method1: function() { /*...*/ }, method2: function() { /*...*/ } }
Alternatively, you can dynamically add your methods:
$.extend(MyClass.prototype, { method1: function() { }, method2: function() { } });
And finally, you can provide your own class creator:
var CreateClass = function(){ return function(){ this.initialize.apply(this, arguments); }; };
Eugene lazutkin
source share