美文网首页
javascript学习笔记--Date(日期)两个对象属性

javascript学习笔记--Date(日期)两个对象属性

作者: 持续5年输出bug | 来源:发表于2018-10-23 22:49 被阅读0次

两个属性:
1.constructor,语法:object.constructor
返回创建此对象的Date 函数的引用,注意不是函数

  var a=new Date();
  var b=new Number();
  var c=new String();
  console.log(a.constructor);
  console.log(b.constructor);
  console.log(c.constructor);

打印结果:
ƒ Date() { [native code] }
ƒ Number() { [native code] }
ƒ String() { [native code] }

 var a=new Date();
  if(a.constructor==Date){
    document.write(a)
  }
  else{
    alert("it not Date")
  }

1.prototype,可以向对象添加属性和方法
语法object.prototype.name=value
<button onclick="myFunction()">点我</button>
Date.prototype.myMet=function()
{
if (this.getMonth()==0){this.myProp="January"};
}
else{
alert("haha")
}

相关文章

网友评论

      本文标题:javascript学习笔记--Date(日期)两个对象属性

      本文链接:https://www.haomeiwen.com/subject/yofvzftx.html