Allen Wirfs-Brock (2013-08-27T23:14:29.000Z)
domenic at domenicdenicola.com (2013-09-09T01:46:59.017Z)
On Aug 27, 2013, at 3:49 PM, David Herman wrote: > On Aug 27, 2013, at 9:47 AM, Filip Pizlo <fpizlo at apple.com> wrote: > >> I do. Placing named properties on arrays makes sense. Consider a matrix implemented as a Float32Array, with named properties telling you the numRows and numCols. Just one example. > > There are of course other ways to achieve this that don't involve patching the array object, such as building a data abstraction for matrices that has-a Float32Array, or creating a new array type with additional methods: > > ```js > var Matrix = new ArrayType(float32); > Matrix.prototype.numRows = function() { ... } > // or > Object.defineProperty(Matrix.prototype, { get: function() { ... }, ... }); > ``` or even better: ```js class Matrix extends Float32Array { get numRows() {...} ... } ``` although "Matrix" may be a bad example... Subclasses of Typed Arrays get their own prototype that can add or over-ride inherited methods. The instances of the subclass are still non-extensible according to the current spec. draft.