• 关于this对象


    <!DOCTYPE html>
    <html>
    <head>
        <title>关于this对象</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
        <script>
            function Person(username){
                var _self=this;
                this.username=username;
                /**
                 * setTimeout是window的方法,所以setTime内调用this,也就是调用window,这里开发者经常弄混
                 */
                setTimeout(function(){
                    _self.showName();
                },1000);
            }
            Person.prototype.showName=function(){
                alert(this.username);
            }
    
            var mm=new Person('mm');
    
    
            window.onload=function(){
                var oBtn=document.getElementsByTagName('input')[0];
                var myData=new Data();
                /**
                 * 此处不能直接 oBtn.onclick=myData.showData; 这样写会导入showData中this调用出错
                 * 国为onclick事件是按钮触发的所有this=HTMLInputElement
                 */
                oBtn.onclick=function(){
                    myData.showData();
                };
            }
    
            function Data(){
                this.idx=1024;
            }
            Data.prototype.showData=function(){
                alert(this.idx);
            }
        </script>
    </head>
    <body>
        <input type=button value=查询 />
    </body>
    </html>
  • 相关阅读:
    mybatis入门-1
    try-with-resources 在捕获异常之后自动释放资源 try(){}
    mybatis配置logback
    使用原生的jdbc连接数据库进行查询
    java中的反射
    ajax实现搜索自动补全
    java IO-1 File 2019-07-24
    VMware历史版本
    Centos8.3-NIS
    用户管理
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/3080450.html
Copyright © 2020-2023  润新知