zoukankan      html  css  js  c++  java
  • 创建ECMAScript对象的三种方法

    <script type="text/javascript">

    /**
     * 1.使用构造函数创建Javascript对象
     */
    function Test(name,url)
    {
        this.name='first';
        this.url='www.first.com';
        this.say=function(){alert('my name is '+this.name);}
    }
    $(function(){
        $('#test').bind('keypress',function(){
            var test=new Test();
            test.say();
            });
    })


    /**
     * 2.使用定义法直接定义Javascript对象
     */
    var Test = {};
    Test.name='second';
    Test.url='www.second.com';
    Test.say=function(){alert('my name is '+this.name);}
    $(function(){
        $('#test').bind('keypress',function(){    
        Test.say();
        });
    })

    /**
     * 3.使用JSON法创建Javascipt对象
     */
    var Test={
        name:'third',
        url:'www.third.com',
        say:function(){alert('my name is '+this.name);}
    }
    $(function(){
        $('#test').bind('keypress',function(){
        Test.say();
            });
    })

    </script>

  • 相关阅读:
    调试与分析
    GCC
    汇编
    数据恢复
    TCP/IP
    shell
    vmstat、top
    计算程序运行时间的封装
    protobuf
    c++模板
  • 原文地址:https://www.cnblogs.com/twelve/p/1942876.html
Copyright © 2011-2022 走看看