Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9047003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:47:47+00:00 2026-06-16T11:47:47+00:00

I’ve been reading about jQuery plugins for a while and trying to implement our

  • 0

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'});
              });

and here is the fiddle link
http://jsfiddle.net/6zHP7/8/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:47:48+00:00Added an answer on June 16, 2026 at 11:47 am

    Great undertaking! I have the same quirk as your boss where I do not feel jQuery’s plugin interface is sufficient for advanced plugins.

    I have started a GitHub project just for this purpose: to give jQuery plugins a more OOP API while remaining backwards compatible.

    https://github.com/adamovsky/jQuery-Plugin-Pattern

    I also started writing a blog post that will go with it:

    http://milan.adamovsky.com/2012/12/jquery-plugin-pattern-30.html

    Feel free to join the effort and contribute.

    Some of the issues I see with your pattern are addressed in my pattern – such as the use of .data(). The other issue I see is that each call to your plugin will instantiate the class.

    All in all, it’s quite an ambitious thing to do and more difficult than it looks due to the edge use cases that can easily make your plugin crash and burn if not addressed (as I found out in my earlier attempts at marrying OOP with jQuery).

    Milan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a jquery bug and I've been looking for hours now, I can't
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.