Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda