h5~js~对象(3)

对象

时间对象

<!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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值