Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/typedObjects.js

Issue 5656302898380800: Issue 260 - [Typed objects] Implement type inheritance (Closed)
Patch Set: Created April 22, 2014, 3:31 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/typedObjects/objectTypes.js » ('j') | lib/typedObjects/objectTypes.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
}
« no previous file with comments | « no previous file | lib/typedObjects/objectTypes.js » ('j') | lib/typedObjects/objectTypes.js » ('J')

Powered by Google App Engine
This is Rietveld