• JavaScript对象直接量里的this关键字


    <html>
    <head>
    <title>新羿集团</title>
    </head>
    <script type='text/javascript'>
        function People()
        {        
            this.age=9;        
            
            //obj是对象直接量,在对象直接量中使用this关键字,this引用的不是调用对象,而是实例化的对象,和new Fun()的函数Fun里面this引用的需要实例化的对象一样
            var obj={SetAge:function(num){this.age=num;},GetAge:function(){return this.age;}};
            obj.SetAge(99);
            alert(obj.GetAge())
            //return obj;
        }

        var p=new People();
        alert(p.age);//如果People返回obj的话,弹出99,否则返回9.
        alert(window.age)//弹出undefined



        
    </script>
    <body>
    <input type='text' name='userName'/>
    <input type='text' name='password'/>
    <input type='button' value='确认' onClick="myOpen();"/>
    </body>
    </html>
  • 相关阅读:
    CSS 选择器之复合选择器
    答辩ppt
    开题报告
    ADS1110/ADS1271
    电感、磁珠和零欧电阻的区别
    ROM、RAM、DRAM、SRAM和FLASH区别
    运放的带宽
    ADC 分辨率和精度的区别
    Verilog
    C语言 文件读取
  • 原文地址:https://www.cnblogs.com/mxw09/p/1766401.html
Copyright © 2020-2023  润新知