zoukankan      html  css  js  c++  java
  • es6

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <button>333</button>
        <script type="text/javascript">
            var that ;
            class test
            {
                constructor(uname, age) {
                    that = this;
                    console.log(this)
                    this.uname = uname
                    this.age = age;
                    this.btn = document.querySelector('button');
                    this.btn.onclick = this.sing;
                }

                sing() {
                    //按钮点击的时候,this指向是调用者button,如果想要调用uname 需要用that这种方式
                    console.log(this)
                    console.log(that.uname)
                }
            }

            class child extends test {
                constructor(uname, age) {
                    // super(uname, age)  //如果没有super(),直接调用sing,
                    //sing里面的this是指向父类,没有定义会报错
                    this.uname = uname
                    this.age = age;
                }
            }
            // var testObject = new test('lilie', 23)
            // testObject.sing()  //this指向是test这个对象
            var childObj = new child('lile', 25)
            childObj.sing()
        </script>
    </body>
    </html>

  • 相关阅读:
    系统架构
    创造HTTPS的是个神
    为Chrome开发插件提高工作效率
    Javascript 控制style 小结
    svcutil 生成代理类时的问题
    xeam Build Definition Extension uninstall 卸载
    看看 Delphi XE2 为 VCL 提供的 14 种样式
    FireMonkey 绘图(1)
    终于, Delphi XE2 携带 GDI+ 库了
    关于禁止程序重复启动的另一种需要与实现
  • 原文地址:https://www.cnblogs.com/agang-php/p/11483049.html
Copyright © 2011-2022 走看看