Skip to content

Instantly share code, notes, and snippets.

@jeffreymeng
Last active October 28, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreymeng/28c120f3b12aafd0dd62c1fa6dac949d to your computer and use it in GitHub Desktop.
Save jeffreymeng/28c120f3b12aafd0dd62c1fa6dac949d to your computer and use it in GitHub Desktop.
Jquery Replacement Utility Code
//this is just the base code. To see a usage example, see Jquery-Replacement-Utility-Code-example-code.js
var getElement = function(selector) { // or var $ = function(selector) {
var wrapper = document.querySelector(selector);
// get Dom wrapper.
//function to add custom functions to the wrapper.
this.addFunction = function(name, code) {
// if code is undefined, assume name is an object with name:function pairs
//enumerate the object name
if (!code) {
for (var key in name) {
//make sure item is not a prototype
if (name.hasOwnProperty(key)) {
var value = name[key];
//set function name in the wrapper to the value(function code)
wrapper[key] = value;
}
}
}
//there is only one function being defined. Set the name to the function(code)
else {
wrapper[name] = code;
}
};
//add utility functions here
return wrapper;
};

jQuery Utility Code Wrapper

Ths script is useful if you are making a libary that needs to do some jQuery-like functonality or are trying to make a jQuery plugin into a Javascript Liabry without jQuery. You can find some utility code to replace certain jQuery functions at http://youmightnotneedjquery.com/ To see usage example, see the Jquery-Replacement-Utility-Code-example-code.js

This code is in the public domain (however a link back to this page would be appreciated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment