zoukankan      html  css  js  c++  java
  • 如何区别ES5和ES6创建类(异同点)

    1、ES5创建类

    function Point(x,y,z){
    	this.x = x;
    	this.y = y;
    	this.z = z;
    }
    
    Point.prototype.toString = function(){
    	return '(' + this.x + ',' + this.y + ',' + this.z + ')';
    }
    
    var p = new Point(23,67,98);
    console.log(p,typeof p,typeof Point,Point === Point.prototype.constructor);

    2、ES6创建类

    class Point{
    	constructor(x,y,z) {
    	    this.x = x;
    	    this.y = y;
    	    this.z = z;
    	}
    	
    	toString(){
    		return '(' + this.x + ',' + this.y + ',' + this.z + ')';
    	}
    }
    
    let p = new Point(89,56,12);
    console.log(p,typeof p,typeof Point,Point === Point.prototype.constructor);
    

    3、运行结果

    Point { x: 23, y: 67, z: 98 } 'object' 'function' true
    
  • 相关阅读:
    NTP服务器
    sublime中文设置
    13、软件定时器
    晶振和CPU周期
    红外通信协议
    KEIL使用时的一些配置
    STM32 的内部 FLASH
    STM32的程序下载
    2、触摸屏
    目录
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313728.html
Copyright © 2011-2022 走看看