Date.prototype.dateAdd = function (interval, number) {
var d = this;
var k = { 'y': 'FullYear', 'q': 'Month', 'm': 'Month', 'w': 'Date', 'd': 'Date', 'h': 'Hours', 'n': 'Minutes', 's': 'Seconds', 'ms': 'MilliSeconds' };
var n = { 'q': 3, 'w': 7 };
eval('d.set' + k[interval] + '(d.get' + k[interval] + '()+' + ((n[interval] || 1) * number) + ')');
return d;
}
The above extension code is not very clear. Can someone explain it to me? ? ? The meaning of each line
给我你的怀抱2017-05-19 10:14:32
eval(string) The eval() function can calculate a string and execute the JavaScript code in it.
d is the date object produced by new.
The entire code is just a spelling js script string and then executed.