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 594609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:58:20+00:00 2026-05-13T15:58:20+00:00

I was building a large web script with jquery. It does various things and

  • 0

I was building a large web script with jquery. It does various things and one of them is interacting with the DOM elements. I used a simple JavaScript function

function mymainclass() {

// declared variables here
this.var1 = new String
// Some functions
this.fn1 = function () { ... }

}

After that, I added other functions using the prototype function in JavaScript.

mymainclass.prototype.afn1 = function () {
...
}

I made a good progress using this methodology, finished writing around 300 lines before I read the Appendix C in “learning Jquery” book. It was about Javascript closures, and it recommended that I use jQuery fn function. So instead of adding functions by prototype I would use:

jQuery.fn.afn1 = function() {
....
return this;
}

I re-factored the whole code from scratch. I was happy because of the new usage

$('..').afn1('..','..',...);

which is much more better in coding; but when I was trying things in my new code, I noticed that it’s much SLOWER than the old one. The old code speed is 50.56ms in total compared to 488ms when the jQuery.fn was used.

I would appreciate any advice about the jQuery plug-ins methodology. I’m afraid that after going 4000 or 5000 lines in my script I find it quite slow and will be obliged to re-factor the code from scratch. What shall I do? Did you find the same issue?

I would also like to know how do you optimize a script so it runs quicker. I use FireBug to track the speed.

  • 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-05-13T15:58:20+00:00Added an answer on May 13, 2026 at 3:58 pm

    Normally you’d want to use the jQuery plugin authoring when you are targeting DOM.

    If you are familiar with the javascript prototype and writing more complex apps, it might be a good idea to write your code using native inheritance first, and then add a jQuery plugin to simplify DOM implementation.

    Prototype is a fast and memory-effective way of extending your javascript code, since every instance inherits the same prototype methods without the need for duplicates.

    I tend to write the app in a native environment and then add a plugin if needed:

    myClass = function(elem) {
        this.elem = elem;
    }
    
    myClass.prototype = {
        myMethod: function() {
            // do stuff
            this.elem.className = 'foo';
        }
    }
    
    $.fn.myClass = function() {
        return this.each(function() {
            var instance = new myClass(this);
            instance.myMethod();
        }
    };
    

    Now you can use this class i two ways:

    $('#elem').myClass();
    

    or:

    var id = document.getElementById('elem');
    var instance = new myClass(id);
    instance.myMethod();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 311k
  • Answers 311k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're storing the date the hash was last retrieved,… May 13, 2026 at 10:17 pm
  • Editorial Team
    Editorial Team added an answer You don't need Linq to do that : string[] selectedColumns… May 13, 2026 at 10:17 pm
  • Editorial Team
    Editorial Team added an answer CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f); uses float constants.… May 13, 2026 at 10:17 pm

Related Questions

So, I've been tossing this idea around in my head for a while now.
Until the preview release yesterday of ASP.NET MVC I had been desperately needing a
I'm building an e-commerce website with a large database of products. Of course, is
I have a large set of classic ASP pages to convert. I will be
A friend and I have been discussing what's the best way to send large

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.