-
-
Notifications
You must be signed in to change notification settings - Fork 804
/
Copy pathindex.js
59 lines (51 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var hasClass = require( '@stdlib/utils/detect-class-support' )();
var evil = require( './../lib' );
function compile( ctor ) {
var name;
var str;
name = ctor.match( /^(\w*)Array$/ )[ 1 ];
name += 'DataArray';
str = '';
str += '(function create(){';
str += '"use strict";';
if ( hasClass ) {
str += 'class '+name+' extends '+ctor+'{';
str += 'constructor(x){';
str += 'super(x);';
str += '}';
str += '}';
} else {
str += 'function '+name+'(){';
str += 'if (!(this instanceof '+name+')){';
str += 'return new '+name+'();';
str += '}';
str += 'ctor.call(this);';
str += 'return this;';
str += '}';
str += name+'.prototype = Object.create('+ctor+'.prototype);';
str += name+'.prototype.constructor = '+name+';';
}
str += 'return '+name+';';
str += '})();';
return str;
}
var ctors;
var fcn;
var i;
ctors = [
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'Array'
];
for ( i = 0; i < ctors.length; i++ ) {
fcn = evil( compile( ctors[i] ) );
console.log( fcn.toString() );
}