Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Commit 2479a65

Browse files
authored
Merge pull request #6 from wizard04wsu/dev
Convert to JavaScript module
2 parents f0bf3be + 5e2a796 commit 2479a65

9 files changed

Lines changed: 636 additions & 634 deletions

File tree

README.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
# JavaScript Class Implementation
22

3-
This no longer works in IE 11.
4-
53
This implementation allows for classes to be given protected access to items in a super-class.
64

5+
This is a JavaScript module.
6+
77
---
88

99
## Creating subclasses
1010

11-
**<samp style="background-color:transparent">*Class*.extend([*options*])</samp>**
11+
**<samp>*Class*.extend([*options*])</samp>**
1212

1313
Creates a new class that inherits from the parent class.
1414

1515
Parameters:
16-
- *options* {object}
16+
- **<code>*options*</code>** {object}
1717
This can include any of the following:
1818

19-
- className {string}
20-
Used as `.name` for the class constructor and in `.toString()` for instances of the class. If not specified, it will be the same as the parent class.
19+
- **<code>className</code>** {string}
20+
Used for the `name` property of the class constructor, and in the `toString` method for instances of the class. If not specified, it will be the same as the parent class.
2121

22-
- constructorFn {function}
23-
Initializes new instances of the class. A 'Super' function is passed as the first argument; <a href="#user-content-super">see below.</a>
22+
- **<code>constructorFn</code>** {function}
23+
Initializes new instances of the class.<br><br>
24+
**<samp>*options*.constructorFn(*Super*[, ...])</samp>**<br><br>
25+
**<code>*Super*</code>** {function} is to be called from inside `constructorFn` to initialize the class, using the class's parent's constructor. It should be called as soon as possible, before using the `this` keyword, to ensure that the instance is properly initialized.<br><br>
26+
Additionally, <code>*Super*</code> provides access to protected members (<a href="#protected-members">see below</a>).
2427

25-
- returnFn {function}
26-
Returns a value when the constructor is called without using the 'new' keyword.
27-
28-
### <span id="super">The 'Super' function</span>
29-
30-
The first argument of the 'constructorFn' option is a function required to instantiate the class using the parent class' constructor. Basically, it acts like the 'super' keyword in ES6. It should be called as soon as possible inside the constructor, before using the 'this' keyword, to ensure that the instance is properly initialized.
31-
32-
**<samp id="super">*options*.constructorFn(*Super*[, *arg1*[, ...]])</samp>**
28+
- **<code>returnFn</code>** {function}
29+
Returns a value when the constructor is called without using the `new` keyword.
3330

3431
#### Example
3532

@@ -73,7 +70,7 @@ s.whatAmI(); //I am a rectangle. I am a square.
7370

7471
### Protected members
7572

76-
Additionally, a class can give its descendants protected access to its private variables. Once <code>*Super*()</code> is called within the constructor, the protected properties of its parent class are made available via <code>*Super*.protected</code>. This object will be available to child classes as well; any additions/deletions/overloads of its members that are made here in the constructor will be reflected in the class' descendants.
73+
A class can give its descendants protected access to its private variables. Once <code>*Super*</code> is called within the constructor, the protected properties of its parent class are made available via **<code>*Super*.protected</code>**. This object will be available to child classes as well; any additions/deletions/overloads of its members that are made here in the constructor will be reflected in the class' descendants.
7774

7875
#### Example
7976

@@ -131,12 +128,3 @@ let c = new Cuber(5);
131128
132129
c.cube(); //125
133130
```
134-
135-
136-
---
137-
138-
## Avoid conflicts between scripts
139-
140-
**<samp>Class.noConflict()</samp>**
141-
142-
Restores `Class` to what it was before this script replaced it. The return value is this implementation of Class, so it can be assigned to another variable.

src/Class.js

Lines changed: 0 additions & 210 deletions
This file was deleted.

0 commit comments

Comments
 (0)