Created
February 13, 2012 03:10
-
-
Save mattpat/1813119 to your computer and use it in GitHub Desktop.
Just the Basics, for people who hate JavaScript libraries (like me!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.