Skip to content

Instantly share code, notes, and snippets.

@mattpat
Created February 13, 2012 03:10
Show Gist options
  • Save mattpat/1813119 to your computer and use it in GitHub Desktop.
Save mattpat/1813119 to your computer and use it in GitHub Desktop.
Just the Basics, for people who hate JavaScript libraries (like me!)
/*
I've never been a fan of JavaScript frameworks.
These three functions are all I ever really need!
*/
/* convenient DOM element lookup */
function $(el){
return document.getElementById(el);
}
/* easy closure generation */
Function.prototype.bind = function(scope){
var __self = this;
return function(){
return __self.apply(scope, arguments);
};
};
/* simple inheritance, the JavaScript way */
Function.prototype.extends = function(superclass){
this.superclass = superclass;
this.prototype = Object.create(superclass.prototype, {
constructor: {
value: this,
enumerable: false,
writable: true,
configurable: true
}
});
};
@mattpat
Copy link
Author

mattpat commented Feb 13, 2012

The first two functions are rough bastardizations of Prototype functions from the good ol' days. The third function is a slight adaption of Node's util.inherits method.

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