<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
</head>
<body>
<script language="javascript" type="text/javascript">
    function Person(){
        this.age="18";
        this.name="Joho";

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
</head>
<body>
<script language="javascript" type="text/javascript">
    function Person(){
        this.age="18";
        this.name="Joho";
        this.sex="Girl";
        this.speak=function(){
            document.write("Hi,I'm speaking..."+"<br>");
        }
        this.run=run;
    }
    function run(){
        document.write("Hi, I'm running....");
    }
   
    var person=new Person();

    person.height=180;//添加属性
    document.write("name="+person.name+"<br>")
    document.write("age="+person.age+"<br>");
    //使用[] 访问对象的属性和方法

    document.write("age="+person["age"]+"<br>");

     var person2=new Person();//

     document.write("name="+person.height+"<br>")//person2中并没有添加height属性,所以会出现错误提示!   


    person.speak();
    person.run();

     //删除属性和方法

    delete person.age; //删除了该属性后,输出:name=undefined    delete person.speak;

    person.height=null; //对象的废除

//无用的对象实例会耗用大量的内存空间.废除不再使用的对象来释放内存空间是一个良好的编程习惯.

在javascript中,当一个对象没有变量引用时,该对象就被废除了,在适当时机于用存储单元收集程序会将其

作为垃圾将其从内存中清除,所以要废除对象可以将该对象的所有引用设置为null

 

    window.setTimeout("person.run()",2000);//设置过2秒钟执行!
</script>
</body>
</html>


        this.sex="Girl";
        this.speak=function(){
            document.write("Hi,I'm speaking..."+"<br>");
        }
        this.run=run;
    }
    function run(){
        document.write("Hi, I'm running....");
    }
   
    var person=new Person();

    person.height=180;//添加属性
    document.write("name="+person.name+"<br>")
    document.write("age="+person.age+"<br>");
    //使用[] 访问对象的属性和方法

    document.write("age="+person["age"]+"<br>");

     var person2=new Person();//

     document.write("name="+person.height+"<br>")//person2中并没有添加height属性,所以会出现错误提示!   


    person.speak();
    person.run();

     //删除属性和方法

    delete person.age; //删除了该属性后,输出:name=undefined    delete person.speak;

    person.height=null; //对象的废除

//无用的对象实例会耗用大量的内存空间.废除不再使用的对象来释放内存空间是一个良好的编程习惯.

在javascript中,当一个对象没有变量引用时,该对象就被废除了,在适当时机于用存储单元收集程序会将其

作为垃圾将其从内存中清除,所以要废除对象可以将该对象的所有引用设置为null

 

    window.setTimeout("person.run()",2000);//设置过2秒钟执行!
</script>
</body>
</html>

 

 

with的使用

 

Code
posted on 2008-12-12 15:05  poop  阅读(265)  评论(0编辑  收藏  举报