zoukankan      html  css  js  c++  java
  • ECMA Script 6_ 类 class

    类 class

    ES6 提供了更接近传统语言的写法,引入了 Class(类)这个概念,作为对象的模板。

    通过 class 关键字,可以定义类 class

    新的 class 写法只是让对象原型的写法更加清晰、更像面向对象编程的语法而已

    类的所有方法都定义在类的 prototype 属性上面,constructo() 也是类原型的 constructor()

    • class Point {
          constructor(x, y) {    /* 构造方法,实例  = new 类 */
              this.x = x;
              this.y = y;
          };
      
          toString() {
              return '(' + this.x + ', ' + this.y + ')';
          };
      };
      
      /**** 子类 继承 父类 ****/
      class myPoint extends Person {
          constructor(x, y, color){    /* 构造方法如果不写,系统默认也会创建,并在内调用 super() */
              super(x, y);    /* 调用父类的构造方法,继承父类的 属性 和 方法 */
              this.color = color;
          };
          
          sayIt(){    /* 不再需要 function 关键字 */
              return 'This is a '+color+'point('+x+', '+y+')';
          };
      };
    • 类的内部所有定义的方法,都是不可枚举的(non-enumerable)
    • 2

    4

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    55

    5

    5

    5

    5

    5

    5

    5

    5

    5

    55

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    5

    --------小尾巴 ________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...
  • 相关阅读:
    (一〇八)iPad开发之横竖屏适配
    ZOJ 1414:Number Steps
    HDU 1391:Number Steps
    ZOJ 1871:Steps
    POJ 2590:Steps
    POJ 2629:Common permutation
    POJ 2562:Primary Arithmetic
    POJ 2505:A multiplication game
    HDU 1517:A Multiplication Game
    POJ 3650:The Seven Percent Solution
  • 原文地址:https://www.cnblogs.com/tianxiaxuange/p/10130173.html
Copyright © 2011-2022 走看看