let d = Date.prototype;
  Object.defineProperties(d, {
    'year': {
      get: function () { return this.getFullYear() },
      set: function (y) { this.setFullYear(y) }
    },
    'month': {
      get: function () { return this.getMonth() + 1 },
      set: function (m) { this.setMonth(m - 1) }
    },
    'nowTime': {
      get: function () { return `${this.getFullYear()}-${this.getMonth() + 1}-${this.getDate()} ${this.getHours()}:${this.getMinutes()}:${this.getSeconds()}` }
    }
  });
  d.asd = function asd(date) {
    return date || this.getDate();
  }
  let date = new Date();
  date.nowTime; //2019-8-18 13:45:1
  date.year; //1999
  date.month; //10
  date.year = 1999;
  date.month = 10;
  date.year; //1999
  date.month; //10
  date.nowTime; // 1999-10-18 13:45:34

 

  //各种类型的构造函数
  console.log(String.prototype);
  console.log(Number.prototype);
  console.log(Array.prototype);
  console.log(Object.prototype);
  console.log(Date.prototype);

 

相关文章:

  • 2021-07-23
  • 2022-01-12
  • 2021-11-06
  • 2021-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-08-01
  • 2021-12-04
相关资源
相似解决方案