Приватный метод проверки ввода

335
15 августа 2017, 17:03

Добрый вечер, сделал приватный метод _isChannelValid(channelNumber) проверки ввода. Но он выдает ошибку _isChannelValid is not defined. Подскажите как правильно сделать приватный метод проверки на ввод чисел от 1 до 99?

class TV {
  constructor() {
    this._power = false;
    this._channel = 1;
    this._lastChannel = 1;
  }
  power() {
    if (this._power) {
      this._power = false;
      this._lastChannel = this._channel;
    } else {
      this._power = true;
      console.log(`TV is on. The channel is #${this._channel}`);
    }
    if (this._power) {
      this._channel = 0;
    } else {
      this.selectChannel(this._lastChannel);
    }
  }
  _isChannelValid(channelNumber) {
    const channelCheck = (!Number.isInteger(channelNumber) || channelNumber < 1 || channelNumber > 99);
    return channelCheck;
  }
  selectChannel(channelNumber) {
    if (_isChannelValid(channelNumber)) {
      return false;
    } else {
      this._channel = channelNumber;
      console.log(`Switch to channel #${this._channel}`);
    }
    return true;
  }
  info() {
    if (this._power) {
      console.log('TV is on');
    } else {
      console.log('TV is off');
    }
    console.log(`The channel is ${this._channel}`);
  }
}
const tv = new TV();
/*
tv.power();
tv.selectChannel(8);
tv.info;
 */
Answer 1
if (this._isChannelValid(channelNumber)) {
...
tv.info();
READ ALSO
Нужен совет по реализации алгоритма

Нужен совет по реализации алгоритма

ПриветПишу веб-приложение, которое обращается к API, получает JSON, обрабатывает и выводит на экран полученные данные

226
Прототипы - присваивание свойства

Прототипы - присваивание свойства

Есть задача: при отсутствии textContent'а - перенять принцип работы innerText'а

299
Как установить value по умолчанию в redux form?

Как установить value по умолчанию в redux form?

Недавно начала изучение redux и столкнулся с проблемой, не знаю как поставить дефолтное значениеВот пример кода:

420