1 | // Note: This file is used by the file ./index.js
|
2 |
|
3 | // factory function which defines a new data type MyType
|
4 | function factory (type, config, load, typed) {
|
5 | // create a new data type
|
6 | function MyType (value) {
|
7 | this.value = value
|
8 | }
|
9 | MyType.prototype.isMyType = true
|
10 | MyType.prototype.toString = function () {
|
11 | return 'MyType:' + this.value
|
12 | }
|
13 |
|
14 | // define a new data type
|
15 | typed.addType({
|
16 | name: 'MyType',
|
17 | test: function (x) {
|
18 | // test whether x is of type MyType
|
19 | return x && x.isMyType
|
20 | }
|
21 | })
|
22 |
|
23 | // return the construction function, this will
|
24 | // be added to math.type.MyType when imported
|
25 | return MyType
|
26 | }
|
27 |
|
28 | exports.name = 'MyType'
|
29 | exports.path = 'type' // will be imported into math.type.MyType
|
30 | exports.factory = factory
|
31 | exports.lazy = false // disable lazy loading as this factory has side
|
32 | // effects: it adds a type and a conversion.
|