Показать сообщение отдельно
  #4 (permalink)  
Старый 21.04.2018, 01:13
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

Vecktor неправильно написано
class Vector1 {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    add(vector) {
        this.x += vector.x;
        this.y += vector.y;
        return this;
    }
}
class Vector2 {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    static add(vector1, vector2) {
        return new this(vector1.x + vector2.x, vector1.y + vector2.y);
    }
}
console.log('Vector1', new Vector1(1, 2).add(new Vector1(2, 3)));
console.log('Vector2', Vector2.add(new Vector2(1, 2), new Vector2(2, 3)));

Последний раз редактировалось Rise, 21.04.2018 в 01:25.
Ответить с цитированием