Skip to content

Instantly share code, notes, and snippets.

@mailtruck
Forked from benatkin/README.md
Created April 17, 2012 22:56
Show Gist options
  • Save mailtruck/2409673 to your computer and use it in GitHub Desktop.
Save mailtruck/2409673 to your computer and use it in GitHub Desktop.

shiminy: minimal es5-shim

Looking at the ES5 compatibility table, several browsers provide everything often used (i. e. not Object.freeze() and friends) except Function.prototype.bind. So I just inline that. Browsers that don't provide other functions also don't include Object.getOwnPropertyNames, so I used it as my test for including the entire shim.

Note that I haven't tested it yet, and it doesn't work for the six Object functions next to each other in the Safari 5 part of the compatibility chart (Safari 5 is deemed good enough).

Update: I added JSON for IE <= 7. JSON is used in a good number of node.js modules.

yepnope([
{
test: window.JSON,
nope: '//cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js'
}, {
test: Object.getOwnPropertyNames,
nope: "//cdnjs.cloudflare.com/ajax/libs/es5-shim/1.2.4/es5-shim.min.js",
callback: function() {
// from es5-shim referenced above. Copyright the original authors. MIT License.
if(!Function.prototype.bind){var slice=Array.prototype.slice;Function.prototype.bind=function a(a){function d(){if(this instanceof d){var a=Object.create(b.prototype);b.apply(a,c.concat(slice.call(arguments)));return a}else{return b.call.apply(b,c.concat(slice.call(arguments)))}}var b=this;if(typeof b.apply!=="function"||typeof b.call!=="function")return new TypeError;var c=slice.call(arguments);d.length=typeof b==="function"?Math.max(b.length-c.length,0):0;return d}}
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment