@@ -18,6 +18,10 @@ function abstractMatrix(superCtor) {
18
18
* @param {number } [nColumns] - Number of columns of the new matrix
19
19
*/
20
20
class Matrix extends superCtor {
21
+ static get [ Symbol . species ] ( ) {
22
+ return this ;
23
+ }
24
+
21
25
/**
22
26
* Constructs a Matrix with the chosen dimensions from a 1D array
23
27
* @param {number } newRows - Number of rows
@@ -339,7 +343,7 @@ function abstractMatrix(superCtor) {
339
343
repeat ( rowRep , colRep ) {
340
344
rowRep = rowRep || 1 ;
341
345
colRep = colRep || 1 ;
342
- var matrix = new this . constructor ( this . rows * rowRep , this . columns * colRep ) ;
346
+ var matrix = new this . constructor [ Symbol . species ] ( this . rows * rowRep , this . columns * colRep ) ;
343
347
for ( var i = 0 ; i < rowRep ; i ++ ) {
344
348
for ( var j = 0 ; j < colRep ; j ++ ) {
345
349
matrix . setSubMatrix ( this , this . rows * i , this . columns * j ) ;
@@ -929,7 +933,7 @@ function abstractMatrix(superCtor) {
929
933
var n = this . columns ;
930
934
var p = other . columns ;
931
935
932
- var result = new this . constructor ( m , p ) ;
936
+ var result = new this . constructor [ Symbol . species ] ( m , p ) ;
933
937
934
938
var Bcolj = new Array ( n ) ;
935
939
for ( var j = 0 ; j < p ; j ++ ) {
@@ -1010,7 +1014,7 @@ function abstractMatrix(superCtor) {
1010
1014
var p = other . rows ;
1011
1015
var q = other . columns ;
1012
1016
1013
- var result = new this . constructor ( m * p , n * q ) ;
1017
+ var result = new this . constructor [ Symbol . species ] ( m * p , n * q ) ;
1014
1018
for ( var i = 0 ; i < m ; i ++ ) {
1015
1019
for ( var j = 0 ; j < n ; j ++ ) {
1016
1020
for ( var k = 0 ; k < p ; k ++ ) {
@@ -1028,7 +1032,7 @@ function abstractMatrix(superCtor) {
1028
1032
* @returns {Matrix }
1029
1033
*/
1030
1034
transpose ( ) {
1031
- var result = new this . constructor ( this . columns , this . rows ) ;
1035
+ var result = new this . constructor [ Symbol . species ] ( this . columns , this . rows ) ;
1032
1036
for ( var i = 0 ; i < this . rows ; i ++ ) {
1033
1037
for ( var j = 0 ; j < this . columns ; j ++ ) {
1034
1038
result . set ( j , i , this . get ( i , j ) ) ;
@@ -1075,7 +1079,7 @@ function abstractMatrix(superCtor) {
1075
1079
if ( ( startRow > endRow ) || ( startColumn > endColumn ) || ( startRow < 0 ) || ( startRow >= this . rows ) || ( endRow < 0 ) || ( endRow >= this . rows ) || ( startColumn < 0 ) || ( startColumn >= this . columns ) || ( endColumn < 0 ) || ( endColumn >= this . columns ) ) {
1076
1080
throw new RangeError ( 'Argument out of range' ) ;
1077
1081
}
1078
- var newMatrix = new this . constructor ( endRow - startRow + 1 , endColumn - startColumn + 1 ) ;
1082
+ var newMatrix = new this . constructor [ Symbol . species ] ( endRow - startRow + 1 , endColumn - startColumn + 1 ) ;
1079
1083
for ( var i = startRow ; i <= endRow ; i ++ ) {
1080
1084
for ( var j = startColumn ; j <= endColumn ; j ++ ) {
1081
1085
newMatrix [ i - startRow ] [ j - startColumn ] = this . get ( i , j ) ;
@@ -1098,7 +1102,7 @@ function abstractMatrix(superCtor) {
1098
1102
throw new RangeError ( 'Argument out of range' ) ;
1099
1103
}
1100
1104
1101
- var newMatrix = new this . constructor ( indices . length , endColumn - startColumn + 1 ) ;
1105
+ var newMatrix = new this . constructor [ Symbol . species ] ( indices . length , endColumn - startColumn + 1 ) ;
1102
1106
for ( var i = 0 ; i < indices . length ; i ++ ) {
1103
1107
for ( var j = startColumn ; j <= endColumn ; j ++ ) {
1104
1108
if ( indices [ i ] < 0 || indices [ i ] >= this . rows ) {
@@ -1124,7 +1128,7 @@ function abstractMatrix(superCtor) {
1124
1128
throw new RangeError ( 'Argument out of range' ) ;
1125
1129
}
1126
1130
1127
- var newMatrix = new this . constructor ( endRow - startRow + 1 , indices . length ) ;
1131
+ var newMatrix = new this . constructor [ Symbol . species ] ( endRow - startRow + 1 , indices . length ) ;
1128
1132
for ( var i = 0 ; i < indices . length ; i ++ ) {
1129
1133
for ( var j = startRow ; j <= endRow ; j ++ ) {
1130
1134
if ( indices [ i ] < 0 || indices [ i ] >= this . columns ) {
0 commit comments