JavaScript笔记(3)

对象属性的晚绑定

    <script language="javascript">
    //创建对象
        var object = new Object();
    //绑定属性name并赋值    
        object.name = "Tom";
    //绑定方法
        object.hello = function(){
            alert("Welcom!");
        }
    //执行方法    
        object.hello();
    //删除方法    
        delete object.hello;
    //方法删除,失效    
        object.hello();
    </script>

============================================
    <script language="javascript">
    //创建对象
        var object = new Object();
    //绑定属性name并赋值    
        object.name = "Tom";
    //绑定方法
        object.sayHello = function(){
            alert(this.name);
        }
        
        object.syaHello2 = function(name){
            this.name = name;
            alert(this.name);
        }
        
        object.sayHello();
        object.syaHello2("Jack!");
    </script>

你可能感兴趣的:(JavaScript)