Skip to content
Browse files

Keep prototype

  • Loading branch information...
1 parent d8094b4 commit fccbf65aedb608a0a1e50cc15922b5b148bb5a37 @schickling committed Sep 26, 2013
Showing with 23 additions and 16 deletions.
  1. +2 −1 .jshintrc
  2. +9 −8 src/timemachine.js
  3. +11 −6 timemachine.js
  4. +1 −1 timemachine.min.js
View
3 .jshintrc
@@ -20,6 +20,7 @@
"loopfunc": true,
"globals": {
"timemachine": true,
- "define": true
+ "define": true,
+ "Date": true
}
}
View
17 src/timemachine.js
@@ -15,26 +15,27 @@
}
})('timemachine', function () {
- var WindowDate = window.Date,
+ var OriginalDate = Date,
Timemachine = {
dateString: 'Wed Dec 25 1991 13:12:59 GMT',
apply: function () {
var self = this;
- window.Date = function () {
+ Date.prototype = OriginalDate.prototype;
+ Date = function () {
if (arguments.length === 1) {
- return new WindowDate(arguments[0]);
+ return new OriginalDate(arguments[0]);
} else if (arguments.length === 7) {
- return new WindowDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
+ return new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
} else {
- return new WindowDate(self.dateString);
+ return new OriginalDate(self.dateString);
}
};
- window.Date.now = function() {
- var date = new WindowDate(self.dateString);
+ Date.now = function () {
+ var date = new OriginalDate(self.dateString);
return date.getTime();
- }
+ };
},
config: function (options) {
View
17 timemachine.js
@@ -15,22 +15,27 @@
}
})('timemachine', function () {
- var WindowDate = window.Date,
+ var OriginalDate = Date,
Timemachine = {
- dateString: 'December 24, 1990 12:25:00',
+ dateString: 'Wed Dec 25 1991 13:12:59 GMT',
apply: function () {
var self = this;
- window.Date = function () {
+ Date.prototype = OriginalDate.prototype;
+ Date = function () {
if (arguments.length === 1) {
- return new WindowDate(arguments[0]);
+ return new OriginalDate(arguments[0]);
} else if (arguments.length === 7) {
- return new WindowDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
+ return new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
} else {
- return new WindowDate(self.dateString);
+ return new OriginalDate(self.dateString);
}
};
+ Date.now = function () {
+ var date = new OriginalDate(self.dateString);
+ return date.getTime();
+ };
},
config: function (options) {
View
2 timemachine.min.js
@@ -1 +1 @@
-!function(a,b){if("function"==typeof define)define(b);else if("undefined"!=typeof module&&module.exports)module.exports=b();else{var c=b(),d=this,e=d[a];c.noConflict=function(){return d[a]=e,c},d[a]=c}}("timemachine",function(){var a=window.Date,b={dateString:"December 24, 1990 12:25:00",apply:function(){var b=this;window.Date=function(){return 1===arguments.length?new a(arguments[0]):7===arguments.length?new a(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]):new a(b.dateString)}},config:function(a){this.dateString=a.dateString||this.dateString}};return b.apply(),b});
+!function(a,b){if("function"==typeof define)define(b);else if("undefined"!=typeof module&&module.exports)module.exports=b();else{var c=b(),d=this,e=d[a];c.noConflict=function(){return d[a]=e,c},d[a]=c}}("timemachine",function(){var a=Date,b={dateString:"Wed Dec 25 1991 13:12:59 GMT",apply:function(){var b=this;Date.prototype=a.prototype,Date=function(){return 1===arguments.length?new a(arguments[0]):7===arguments.length?new a(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]):new a(b.dateString)},Date.now=function(){var c=new a(b.dateString);return c.getTime()}},config:function(a){this.dateString=a.dateString||this.dateString}};return b.apply(),b});

0 comments on commit fccbf65

Please sign in to comment.
Something went wrong with that request. Please try again.