首页 > 编程语言 > 详细

3. 现代 javascript class 专题 和 异步专题

时间:2019-09-12 19:28:17      阅读:91      评论:0      收藏:0      [点我收藏+]

class 专题

  定义 class

    //es5 类的定义  属性定义在 function 上, 方法定义在原型链上

    function foobar(){

      this.foo_ = ‘foo‘;

      this.bar_ = ‘bar‘;

    }

    foobar.prototype.sayHello = function(){ console.log(‘hello‘) }

    const fb = new foobar();

    fb.sayHello();

    // es6 class 语法

    class foobar2{

      constructor(){

        this.foo_ = ‘foo‘;

        this.bar_ = ‘bar‘;

      }

      sayHello(){ console.log(‘hello‘) }

    }

    const fb2 = new foobar2();

    fb2.sayHello();

  继承

    class father {

      sayHi(){ console.log(‘Hi‘) }

    }

    class son extends father{

      constructor () {

        super();

        this.me=‘son‘

      }

      sayHello(){ console.log(‘hello‘) }

    }

    const son1 = new son();

    // 调用 father 类的 sayHi 方法时 找自己的原型 son.prototype 是否含有这个 方法

    // 通过查看父类的原型判断 是否调用的父类的方法 其中 son.prototype.__proto__=father.prototype

    // 通过 hasOwnProperty 判断

    son1.sayHi();

 

  

异步专题

     

3. 现代 javascript class 专题 和 异步专题

原文:https://www.cnblogs.com/zonehoo/p/11514683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!