javascript - One about date expansion: get the date after adding numbers to the date, year, month, day, etc.; this code is not very clear? ? ?
伊谢尔伦
伊谢尔伦 2017-05-19 10:12:32
0
1
422

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

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
给我你的怀抱

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template