Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
how to change `this` pointer in typescript

I want to create a Image data and rewrite onload function , but this can't point to newImage in typescript. what can i do to make this pointer point to newImage

enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can tell TypeScript which type this should have by adding it as a function parameter:

function onload(this: HTMLImageElement) {
  const {width, height} = this
}

The parameter will be ignored when compiling to JavaScript.

See https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function

about 4 years ago · Juan Pablo Isaza Relatório

0

According to the code you provided I do not see a way to use this pointer as newImg. But you will be able to use const{width,height} = newImg.somethingYouWannaDo().

about 4 years ago · Juan Pablo Isaza Relatório

0

function onload(img){
  const {width, height} = img
}

Isn't onload passed the img?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda