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

Side by Side Diff: lib/typedObjects.js

Issue 5656302898380800: Issue 260 - [Typed objects] Implement type inheritance (Closed)
Patch Set: Fixed inheritance of non-overridden constructors Created April 28, 2014, 7:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/typedObjects/objectTypes.js » ('j') | lib/typedObjects/objectTypes.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 * 51 *
52 * Creating an object instance 52 * Creating an object instance
53 * --------------------------- 53 * ---------------------------
54 * 54 *
55 * var point = Point2D(5, 10); 55 * var point = Point2D(5, 10);
56 * point.rotate(10); 56 * point.rotate(10);
57 * Console.log(point.x + ", " + point.y); 57 * Console.log(point.x + ", " + point.y);
58 * 58 *
59 * The parameters 5 and 10 will be passed to the constructor function defined 59 * The parameters 5 and 10 will be passed to the constructor function defined
60 * for this type. 60 * for this type.
61 *
62 * Type inheritance
63 * ----------------
64 *
65 * var Point3D = Point2D.extend({
66 * z: uint32
67 * }, {
68 * constructor: function(super_, x, y, z)
69 * {
70 * super_(x, y);
71 * ...
72 * }
73 * });
74 *
75 * Extended types can be used wherever their base type is required. The
76 * parameters taken by type.extend() are the same as parameters of
77 * new ObjectType(), the only difference is that properties and methods
78 * of the original type are taken over. Methods and constructors can be
79 * overwritten, they will then get superclass method/constructor as the first
80 * parameter and can call it.
81 *
82 * Common object methods
83 * ---------------------
84 *
85 * All objects inherit from ObjectBase type implicitly and share its methods.
86 * In particular, object.equals() can be used to compare objects:
87 *
88 * var point1 = Point2D(5, 10);
89 * var point2 = Point2D(6, 12);
90 * console.log(point1.equals(point2)); // false
91 * console.log(point1.equals(point1)); // true
92 *
93 * Note that JavaScript comparison operators == and != won't always produce
94 * correct results for typed objects.
61 */ 95 */
62 96
63 function forwardExports(module) 97 function forwardExports(module)
64 { 98 {
65 let moduleExports = require(module); 99 let moduleExports = require(module);
66 for (let key in moduleExports) 100 for (let key in moduleExports)
67 exports[key] = moduleExports[key]; 101 exports[key] = moduleExports[key];
68 } 102 }
69 103
70 forwardExports("typedObjects/primitiveTypes"); 104 forwardExports("typedObjects/primitiveTypes");
71 forwardExports("typedObjects/objectTypes"); 105 forwardExports("typedObjects/objectTypes");
OLDNEW
« 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