Skip to content

Instantly share code, notes, and snippets.

@Skateside
Skateside / extend.js
Created July 29, 2012 22:06
I've been looking at Sugar and RightJS and I figured I'd start playing with my own version. I like what these things do to the language, they make it seem a lot more sensible. Ultimately this would add the ES5 and ES6 methods as well as some more new ones
// This is very similar to the standard implimentation of Object.extend but the
// important difference here is that this method will not overwrite any existing
// method of the source object. This makes it idea for updating native objects.
if (!Object.hasOwnProperty('update')) {
(function () {
'use strict';
var setProp = function (source, property, value) {
Object.defineProperty(source, property, {
@Skateside
Skateside / addEventListener.js
Created July 12, 2012 21:41
I'm working on a polyfill for addEventListener. When it's complete, it will work with custom events, support removeEventListener and support the DOMContentLoaded event
// Shim to make sure that we've got the modern functions and methods that we
// need, namely [].forEach, [].map and Object.keys
(function () {
var undef, // = undefined;
isStringArray = 'a'[0] === 'a', // Used in toObject.
toString = Object.prototype.toString, // Used for class checking.
hasDontEnumBug = !{toSring: null}.propertyIsEnumerable('toString'),