https://github.com/es-shims/es5-shim/blob/v4.0.3/es5-shim.js
<script type="text/javascript">
Wrapper = (function (NativeDate) {
// Date.length === 7
function Wrapper(Y, M, D, h, m, s, ms) {
var length = arguments.length;
console.log(this);
console.log(NativeDate);
console.log(this instanceof NativeDate);
if (this instanceof NativeDate) {
var date = length === 1 && String(Y) === Y ? // isString(Y)
// We explicitly pass it through parse:
new NativeDate(Date.parse(Y)) :
// We have to manually make calls depending on argument
// length here
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
length >= 5 ? new NativeDate(Y, M, D, h, m) :
length >= 4 ? new NativeDate(Y, M, D, h) :
length >= 3 ? new NativeDate(Y, M, D) :
length >= 2 ? new NativeDate(Y, M) :
length >= 1 ? new NativeDate(Y) :
new NativeDate();
// Prevent mixups with unfixed Date object
date.constructor = Wrapper;
console.log('there');
return date;
}
console.log('here');
return NativeDate.apply(this, arguments);
}
Wrapper.prototype = NativeDate.prototype;
Wrapper.prototype.constructor = Wrapper;
// Upgrade Date.parse to handle simplified ISO 8601 strings
Wrapper.parse = function parse(string) {
return NativeDate.parse.apply(this, arguments);
};
return Wrapper;
})(Date);
</script>