Skip to content

Instantly share code, notes, and snippets.

@aaronblohowiak
Forked from jaredatron/object.create.js
Created April 27, 2010 21:11
Show Gist options
  • Save aaronblohowiak/381338 to your computer and use it in GitHub Desktop.
Save aaronblohowiak/381338 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Test</title>
</head>
<body id="test">
<script>
function jaredsCreate(){
(function() {
function create(object){
if (object){
create.prototype = object;
return new create;
}
}
Object.create || (Object.create = create);
})();
};
function crockfordCreate(){
Object.create = function(o){
var F = function(){};
F.prototype = o;
return new F();
};
};
function bench(str, f){
t = new Date();
f();
t2 = new Date();
document.write(str+": "+(t2-t));
}
function test(){
for (var i=0; i < 100000; i++) {
Object.create({});
};
};
crockfordCreate();
bench("crockford", test);
document.write("<br/>");
jaredsCreate();
bench("jared", test);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment