Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!