| Index: lib/typedObjects.js |
| =================================================================== |
| --- a/lib/typedObjects.js |
| +++ b/lib/typedObjects.js |
| @@ -53,16 +53,50 @@ |
| * --------------------------- |
| * |
| * var point = Point2D(5, 10); |
| * point.rotate(10); |
| * Console.log(point.x + ", " + point.y); |
| * |
| * The parameters 5 and 10 will be passed to the constructor function defined |
| * for this type. |
| + * |
| + * Type inheritance |
| + * ---------------- |
| + * |
| + * var Point3D = Point2D.extend({ |
| + * z: uint32 |
| + * }, { |
| + * constructor: function(super_, x, y, z) |
| + * { |
| + * super_(x, y); |
| + * ... |
| + * } |
| + * }); |
| + * |
| + * Extended types can be used wherever their base type is required. The |
| + * parameters taken by type.extend() are the same as parameters of |
| + * new ObjectType(), the only difference is that properties and methods |
| + * of the original type are taken over. Methods and constructors can be |
| + * overwritten, they will then get superclass method/constructor as the first |
| + * parameter and can call it. |
| + * |
| + * Common object methods |
| + * --------------------- |
| + * |
| + * All objects inherit from ObjectBase type implicitly and share its methods. |
| + * In particular, object.equals() can be used to compare objects: |
| + * |
| + * var point1 = Point2D(5, 10); |
| + * var point2 = Point2D(6, 12); |
| + * console.log(point1.equals(point2)); // false |
| + * console.log(point1.equals(point1)); // true |
| + * |
| + * Note that JavaScript comparison operators == and != won't always produce |
| + * correct results for typed objects. |
| */ |
| function forwardExports(module) |
| { |
| let moduleExports = require(module); |
| for (let key in moduleExports) |
| exports[key] = moduleExports[key]; |
| } |