CHANNELS:

All
B
Boban posted 5 years ago
chris posted 5 years ago
Best Reply

Hey Bob, yes for sure, if you're not using a module bundler to import and export files, you can inline the Dot.js code into your main .js file.

All you'd do is change Dot.js here:

export default class Dot {
  constructor(x, y, r, g, b, imageX, imageY) {
    this.x = x
    this.y = y
    this.r = r
    this.g = g
    this.b = b
    this.imageX = imageX
    this.imageY = imageY
  }

  draw(c) {
    c.beginPath()
    c.arc(this.x, this.y, 2, 0, 2 * Math.PI, false)
    c.fillStyle = 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')'
    c.fill()
  }
}

To be inline-able like:

class Dot {
  constructor(x, y, r, g, b, imageX, imageY) {
    this.x = x
    this.y = y
    this.r = r
    this.g = g
    this.b = b
    this.imageX = imageX
    this.imageY = imageY
  }

  draw(c) {
    c.beginPath()
    c.arc(this.x, this.y, 2, 0, 2 * Math.PI, false)
    c.fillStyle = 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')'
    c.fill()
  }
}

So basically, get rid of the export default, place the class in whatever file you'd like to use it, and now you can use it just like in the video.

Let me know if that helps!

1
B
Boban posted 5 years ago

Thanks heaps on your response Chris. Hope all is going well.

0

Want to participate?

Create a free Chris Courses account to begin

or
Sign In

Providing the lift to launch your development career

© 2024 Chris Courses. All rights reserved.