I've been reading about jQuery plugins for a while and trying to implement our plugins in a more oop way. my manager is a c# guy and hates the way jQuery UI calls methods. i wanna use the approach bellow and wanna know your opinion about it. tell me the pros and cons of what i'm trying to use plz. ok this is it as a simple sample.it has works to do but for start:
if(typeof Object.create !== 'function')
{
Object.create = function(o)
{
function F()
{
}
F.prototype = o;
return new F();
};
}
var Car = (function()
{
var openDoor = function(doorNum)
{
alert("door #" + doorNum + " opened");
};
return {
openDoor: openDoor
};
}
)();
(function($, window, document, undefined)
{
$.fn.car = function(options)
{
if(this.length)
{
return this.each(function() {
var myCar = Object.create(Car);
$.data(this, 'car', myCar);
for(var prop in Car)
{
if($.fn[prop] == null)
{
$.fn[prop] = function(params)
{
return this.each(function () {
if($.data(this, "car") == null)
{
throw Error("not implemented function");
}
$.data(this, "car")[prop](params);
}
);
};
}
}
});
}
};
})(jQuery, window, document);
$("#test").on("click", function()
{
$("#test").car().openDoor(1).css({color: 'red'});
});
here is the fiddle link
http://jsfiddle.net/6zHP7/8/