zoukankan      html  css  js  c++  java
  • ES6/5比较

     
    ES6
    function f (x, y, ...a) {
        return (x + y) * a.length
    }
    f(1, 2, "hello", true, 7) === 9
    
    ES5
    function f (x, y) {
        var a = Array.prototype.slice.call(arguments, 2);
        return (x + y) * a.length;
    };
    f(1, 2, "hello", true, 7) === 9;
    ECMAScript 6 
    class Shape {
        constructor (id, x, y) {
            this.id = id
            this.move(x, y)
        }
        move (x, y) {
            this.x = x
            this.y = y
        }
    }
    ECMAScript 5  
    var Shape = function (id, x, y) {
        this.id = id;
        this.move(x, y);
    };
    Shape.prototype.move = function (x, y) {
        this.x = x;
        this.y = y;
    };
    ECMAScript 6  
    class Rectangle extends Shape {
        constructor (id, x, y, width, height) {
            super(id, x, y)
            this.width  = width
            this.height = height
        }
    }
    class Circle extends Shape {
        constructor (id, x, y, radius) {
            super(id, x, y)
            this.radius = radius
        }
    }
    ECMAScript 5  
    var Rectangle = function (id, x, y, width, height) {
        Shape.call(this, id, x, y);
        this.width  = width;
        this.height = height;
    };
    Rectangle.prototype = Object.create(Shape.prototype);
    Rectangle.prototype.constructor = Rectangle;
    var Circle = function (id, x, y, radius) {
        Shape.call(this, id, x, y);
        this.radius = radius;
    };
    Circle.prototype = Object.create(Shape.prototype);
    Circle.prototype.constructor = Circle;
  • 相关阅读:
    POJ 1315 Don't Get Rooked
    POJ 2051 Argus
    POJ 1942 Paths on a Grid
    POJ 2151 Check the difficulty of problems
    POJ 3349 Snowflake Snow Snowflakes
    POJ 1753 Flip Game
    POJ 2392 Space Elevator
    POJ 2385 Apple Catching
    POJ 2356 Find a multiple
    POJ 2355 Railway tickets
  • 原文地址:https://www.cnblogs.com/douglasvegas/p/5899854.html
Copyright © 2011-2022 走看看