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

  • Home
  • SEARCH
  • 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 1808688
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:17:35+00:00 2026-05-17T06:17:35+00:00

What is the best way to create library agnostic wrapper for JS library selectors?

  • 0

What is the best way to create library agnostic wrapper for JS library selectors? I have a custom JS framework, that aims to be as library-agnostic as possible. The problem I have is that for example Mootools enhances the returned DOM element with it’s own specific methods (inject, adopt etc.), and I don’t want these to be visible to the modules, layered on top of the framework (as Nicholas Zakas once described), to prevent misuses/accidents.

As a simple first-aid I created a custom selector that uses Mootools, it then creates custom Element -object/wrapper and hands selected (and enhanced) Mootools DOM element to it, thus the Mootools enhanced methods are not directly visible to the modules above. The problem with this approach is that I lose all the native functionality of the DOM element (value, style etc.) if it’s not specifically coded to the wrapper (Element).

Is there another and/or better way to do this? Something that would extend the native DOM element, thus providing the native properties/methods automatically AND offering advanced functionality through the wrapper (via Mootools, jQuery, whatnot…).

Some example code, how it’s currently done:

/*
 * Wrap the native library element
 */
Element = function(_libElement) {
    // Store native object
    var libElement = _libElement;

    return {
        addClass: function(_class) { libElement.addClass(_class); return this; },
        removeClass: function(_class) { libElement.removeClass(_class); return this; },
        hasClass: function(_class) { return libElement.hasClass(_class); }
    };
};

/*
 * Custom selector
 */
getElement = function(_query) {
    var elements = $$(_query);

    // Wrap each element to Element wrapper
    var num = elements.length;
    while(num--) {
        elements[num] = new Element(elements[num]);
    }

    return elements;
};
  • 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-17T06:17:35+00:00Added an answer on May 17, 2026 at 6:17 am

    My approach would be to not worry about it, just pass back the native DOM element. If someone wants to rely on MooTools’ (or Prototype’s) enhancements to that DOM element, it’s their own lookout. In fact, if you try to prevent those enhancements showing through, I’d say you’re no longer being library-agnostic — instead, you’re being actively discriminatory (for lack of a better word!) against libraries that do native element enhancement. 🙂 Someone using those libraries presumably wants those enhancements.

    If someone is building modules on top of your library, they should be aware of the environment on which they’re building (which doesn’t guarantee that those enhancements exist).

    Somewhat off-topic, but it’s probably worth noting that extending DOM elements directly seems to be going out of fashion. I know that the Prototype guys are actively planning to use wrappers (a’la jQuery) instead in the fullness of time.

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

Sidebar

Related Questions

What is the best way to create redundant subversion repositories? I have a subversion
What is the best way to create fluid width/height rounded corners with jQuery? That
What is the best way to create a custom title for pages in a
What is the best way to create a lock on a file in Perl?
What is the best way to create a fixed width file in C#. I
What is the best way to create a webservice for accepting an image. The
What is the best way to create several scrollable regions in an ActionScript 3
So what's the best way to create new tables in a Sqlite database in
What do you think is the best way to create SEO friendly URLs (dynamically)
Given an existing valid SVG document, what's the best way to create informational popups,

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.