> For the complete documentation index, see [llms.txt](https://docs.cheddar.vihan.org/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cheddar.vihan.org/docs/developing/primitive-objects/class.md).

# Class

You may know what a class is, a "blueprint" for which an object is to be constructed from, but internally they are very simple (the source code contains detailed information of their implementation, [the class implementation](https://github.com/cheddar-lang/Cheddar/blob/master/src/interpreter/core/env/class.es6#L1) may provide additional details). A class has 3 main parts:

```
         Class
           |
  +--------+--------+
  |        |        |
scope    init()  instance
```

**A class&#x20;*****is*****&#x20;a scope**. An instance of a class is really just a scope. This may sound confusing but, think about what a scope *is*, it is a hashmap of variables which can inherit and provides interfacing for accessing it's variables. That sounds just like what a class is.

So what else? A class has an initializer, this is the main part seperating a class from a scope. Here are the steps taken during a class initalization:

1. **Create** an empty scope (this is called the "instance")
2. **Copy** the class's scope to the instance (and the inheriting class's if applicable).
3. **Run** the initializer (`init`) and pass the instance as "self".
4. **Return** the instance.

As you can see, the returned *instance*, is **just a regular scope**, but pre-populated. When executed, methods are passed the scope as a whole. Here's an example:

```javascript
class MyClass() {
  whatIsSelf => self
}

var A = MyClass{};
A.whatIsSelf();   // < Instance of "MyClass" >
```

as you can see, `whatIsSelf` is passed its scope (`A`) by the evaluator, but the scope is not directly attached to `whatIsSelf`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cheddar.vihan.org/docs/developing/primitive-objects/class.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
