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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:37+00:00 2026-06-10T14:26:37+00:00

I recently read a blog post about having your code rely as little on

  • 0

I recently read a blog post about having your code rely as little on the DOM as possible (i.e. keep as much out of the $(document).ready() function as possible). I’ve been successful in doing this with things like creating view modules like this:

var View = function (e) {
  this.element = e;
};

View.prototype = {
  show: function () {
    this.element.fadeIn();
  },
  //More manipulation functions
};

$(document).ready(function () {
  var myView = new View($('#element'));
  myView.show();
});

I can’t seem to find a way to wrap AJAX calls into an object so they’re not depending on the DOM being loaded and so I don’t have to write something like this every time I make an AJAX call:

$.ajax({
  url: "signout.php",
  type: "POST",
  dataType: "json",
  error: function (jqXHR, textStatus, errorThrown) {
    alert('An error occured while trying to log out.');
  },
  success: function (data, textStatus, jqXHR) {
    settingsWidget.getAction('#settings').triggerAction(500, function () {
      WIDGETS.setOnTop('#login', SideEnum.RIGHT);
    });
  },
  complete: function (jqXHR, textStatus) {}
});

Is there a design pattern that I can use to achieve what I’m trying to do? Also, would it be best to pass the jQuery DOM object to the View object or just the selector and grab the DOM object inside of the View object?

  • 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-10T14:26:38+00:00Added an answer on June 10, 2026 at 2:26 pm

    Dirtying up the DOM has always been a problem. Backbone.js is great, it helps give a lot of structure to your code. The module pattern by Douglas Crockford will help provide encapsulation for a lot of your code as well.

    http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

    A great synopsis of some design patterns

    http://addyosmani.com/resources/essentialjsdesignpatterns/book/

    And this is what I currently use as a design pattern

    https://github.com/bmarti44/jq-mod-pat

    What you use is up to you, but you should be fine doing ajax calls with any of these patterns. Hopefully one of these will give you some inspiration.

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

Sidebar

Related Questions

I recently read a blog post about the Reddit hotness formula . The formula
I recently read a post online about rotating text with css. This appealed to
I recently read a post about no longer needing to declare ivars as well
I recently found out about Presenter First and read their whitepapers and blogs, etc.
I recently read an interesting blog post on Anders Hejlsberg's arguments against AOP. The
I've recently read an article http://www.ravelrumba.com/blog/static-cookieless-domain/ about Serving Static Content from a Cookieless Domain
I recently read about a new Google-code hosted (open source) project from Google that
I recently read Ayende's blog post on automatic registration working with XML Configuration. I
I recently read a blog in Nodejitsu and I am wondering how this piece
I recently read an article about password hashing . How are MD5 or SHA1

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.