对象
时间对象
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>时间对象</title>
</head>
<body>
<script>
var now = new Date();
document.write(now);
var year = now.getYear();
var month= now.getMonth();
var day = now.getDay();
alert(year);
alert(month);
alert(day);
document.write(year+"-"+month+"-"+day);
</script>
</body>
</html>
系统对象
分析对象的属性和方法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>分析对象的属性和方法</title>
</head>
<body>
dasjdfasd
<script>
var pro="";
document.bgColor="aqua";
for( pro in document)
{
document.write("document."+pro+"="+document[pro]+"<br>");
}
var q = new function(){
this.hp=100;
this.q=233;
this.move=function(){
document.write("正在移动");
}
}
for(pro in q)
{
document.write("q."+pro+"="+q[pro]+"<br>");
}
</script>
</body>
</html>
对象的创建几种方法
函数来创建对象
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
//通过函数来创建对象
function q(){
var p = new Object();
p.hp=100;
p.act=90;
p.money=200;
p.move=function(){
document.write("正在移动");
}
return p;
}
var qq=new q();
var qqq=new q();
//alert(qq.move());
//alert(qqq.move());
//通过函数将对象初始化进行封装
function w(n,m,b,v){
this.n=n;
this.m=m;
this.b=b;
this.v=v;
this.move=function(){
document.write("正在移动");
}
}
var pp=new w("wq",12,43,54,32);
var ppp = new w("ew",43,54,76);
alert(pp.move());
alert(ppp.move());
var pro="";
for(pro in pp)
{
document.write(pp[pro]);
}
pp.move();ppp.move();
</script>
</body>
</html>
用Object创建对象
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!--<script>
function npc(){
}
var p1=new npc();
p1.name=12;
p1.act=23;
p1.money=34;
p1.move=function(){
document.write("开火");
}
p1.ds=function(){
document.write("飞行");
}
alert(p1.hp);
p1.move();
</script>-->
<script>
var p1=new Object();
p1.name=12;
p1.act=23;
p1.money=34;
p1.move=function(){
document.write("开dsad火");
}
p1.ds=function(){
document.write("飞行");
}
alert(p1.hp);
p1.move();
</script>
</body>
</html>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30545764/viewspace-2121001/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30545764/viewspace-2121001/