Javascript Classes!

Hi! This is a class tutorial!
Here i will explain how to use classes in your code.

What is a class?

A class is a javascript feature, making modularity easy!
It works like a factory, making objects on demand!

Here’s a diagram:
Diagram

Making a class on JavaScript

On Javascript, classes can be done with ease since ES6, with the class keyword!
The following code will explain how to make a ES6 class:

class Car { // <- define a class like this 
  constructor(name, year) { // always put the constructor, it's essential for the class!
    this.name = name; // while on the constructor, use this as the reference to your object
    this.year = year;
    this._kilometers = 0
  }
  drive(kilometers) { // <- this is a method, it is the way we add functions to our class
    this._kilometers =+ kilometers
  }
  get kilometers() { // this is a getter, acts like a variable, but it's a function
    return this._kilometers
  }
}
Using classes with Clips on Wick Editor

Since i couldn’t come up with a simple class based idea for this, here’s some basic class code that makes a class with a clone of a clip attached:

class Clippo {
  constructor(arg) {
    this.arg = arg
    this.clip = clip.clone()
  }
}
1 Like

just wanna show another useful way of linking a clip in the constructor:

class Thing {
    constructor(arg, clip) {
        this.arg = arg;
        this.clip = clip;
    }
}

the only difference is that you are creating the clone outside the constructor, like this:

project.thing1 = new Thing("arg1", mainClip.clone());

1 Like

Oh! That is valid and also more safe, Thank you for the reply!