Загрузка...

Doesnt see the variable in TS methods.

Thread in Node.js created by RichPerson Dec 26, 2023. 210 views

  1. RichPerson
    RichPerson Topic starter Dec 26, 2023 Разработка - https://zelenka.guru/threads/4480553/ 2161 Sep 23, 2019
    Создается экземпляр класса в другом классе. Если прописать console.log в конструкторе - все выводит и видит. Если использовать тоже самое в методах класса бьет ошибку TypeError: Cannot read properties of undefined (reading 'config')
    Хелп
    middleware/index.ts
    [IMG]
    http/index.ts
    [IMG]
     
  2. RichPerson
    RichPerson Topic starter Dec 26, 2023 Разработка - https://zelenka.guru/threads/4480553/ 2161 Sep 23, 2019
    1. RichPerson Topic starter
      юнитошка, that = this - это не прокатило. Теперь undefined that
    2. юнитошка
      RichPerson, попробуй bind и стрелочную функцию
  3. RichPerson
    RichPerson Topic starter Dec 26, 2023 Разработка - https://zelenka.guru/threads/4480553/ 2161 Sep 23, 2019
    [IMG]
    Так, от ошибки я избавился таким методом, теперь вопрос в том, какого хуя undefined
     
  4. sochness
    sochness Jan 1, 2024 1 Feb 28, 2022
    When you pass a method as an argument it loses the `this` reference.
    JS
    this.express.use(this.middleware.removeToken)
    Instead try
    JS
    this.express.use((...args) => this.middleware.removeToken(...args))
     
Loading...
Top