两个属性:
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")
}
网友评论