• 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>
  • 相关阅读:
    placeholder 兼容处理
    扩展 jq 对象方法
    gulp 命令
    v-show、v-if、v-for的使用
    Vue中防抖和节流 --来自官方文档
    Python字符窜取值
    怎么安装redis桌面版?
    Python常用的基本数据类型
    MySQL常用语法
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/mxw09/p/1766401.html
Copyright © 2020-2023  润新知