JSGraphics
The JSGraphics library can be used to easily manipulate an HTML5 Canvas, and is used by Stanford's CS106AJ and CS106AX curricula.
For students: How to read this documentation
This document is intended to read like documentation you might find for any library online. It's a good thing to be able to read it, and see what such documentation might look like. If you're ever working on larger projects, you're very likely to be reading documentation just like this!
Because this is likely the first time you're looking at documentation like this, you'll see some notation and vocabulary you haven't seen before. I'll briefly go over this so you this documentation will be useful to you!
The vocabulary and examples below use knowledge that may come a bit later in the quarter; feel free to ask on Ed or in office hours if you need help interpreting any of the documentation.
Vocabulary
Some of these definitions may seem scary at first. Don't worry, I'll give an example below.
Word | Definition |
---|---|
Class | A blueprint for an object. A class says what an object will contain, and also defines all of its functionality. If an object matches a class, we say that object is an instance of that class. |
Extends | We say that one class extends another if the second class has all the same things as the first class, plus extras or changes (but not deletions). If class B extends class A, we say that B is a subclass of A, and that A is the superclass of B. |
Abstract Class | A class with missing parts. An abstract class says what a subclass will contain, but it doesn't define all of its functionality. You can't really use abstract classes on their own — you have to use one of their subclasses. |
Factory Function | A function that creates an instance of a class. |
Method | A function that's a part of a class's functionality. You can only call normal methods on instances of a class. |
Abstract Method | A method inside an abstract class that's not defined (i.e. that one of the subclasses must define). |
Static Method | A method that's part of a class, not its instances. You can only call static methods on the class itself. |
Field (a.k.a. Instance Variable) | A variable that's part of a class's instances. Each instance of a class will have its own values for each field, and instances don't share fields. It follows, then that you can only access fields from an instance of a class. |
Static Field | A variable that's part of a class, not its instances. You can only access a static field on the class itself. |
Const | Short for constant. It means the value shouldn't ever be modified. |
Vocabulary Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
Notation
When looking through this documentation, you'll see method definitions that look like this:
- function ClassName::methodName(parameter1, parameter2[, optionalParameter="default value"])
- This is a description of what this function does. We have two required parameters, and
one optional parameter. optionalParemeter has a default value of
"default value"
if you omit it.
or this:
- static function ClassName.staticMethod([param1="", param2=""[, param3=""]])
- We have zero required parameters here! You'll notice that we have brackets in brackets. That just means that if we want to give param3, we have to also give param1 and param2. It also means that param1 and param2 have to be together (if you include one, you have to include both. Here's an example:
1 2 3 4 |
|
Something you might notice that you haven't seen before is the ::
in ClassName::methodName
.
This just means that methodName
is a method of ClassName
, and you can't actually call it directly. Example:
1 2 3 4 5 |
|
You might notice that staticMethod
has a .
instead of ::
. This is the reverse of what we just saw:
1 2 3 4 5 6 |
|