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

113
Visualizações
Using a declared class as a function argument in Javascript

I've declared a class gly that accesses a canvas made with node-canvas.

const width = 250;
const height = 250;
const canvas = createCanvas(height, width);
const gly = canvas.getContext("2d");

A separate function (outside that class) takes multiple arrays of [x,y] coordinates and should draw them onto the canvas. That function is initialized as

function drawShape(shapeClass, color, ...shapes) {

whereas shapeclass is gly.

I've already done this successfully without that function, but as I'm drawing so many shapes onto a canvas, I want to clean up the code by making that function draw the shapes whenever needed. The issue is that whenever gly's class functions are called from within function drawShape, nothing happens. There aren't any errors, and color and ...shapes pass perfectly fine into the function, but the function itself does nothing, leaving an empty space on the canvas.

Am I passing gly correctly into drawShape?

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

0

I figured it out - it had nothing to do with how I was using either the functions or the classes. Junk data found itself into an array and threw everything off.

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