Skip to content

Commit a262090

Browse files
committed
implement name with symbol
1 parent b2b5b1f commit a262090

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/interface-prototype.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ export class InterfaceClass {
88
}
99
export class InterfacePrototype{}
1010
export function Interface(...interfaces){
11-
return class extends InterfacePrototype {
11+
let name;
12+
if(typeof interfaces[0] === 'string' || typeof interfaces[0] === 'symbol'){
13+
name = interfaces.shift();
14+
}
15+
else{
16+
name = Symbol();
17+
}
18+
return class InterfaceClassIntance extends InterfacePrototype {
1219
static [Symbol.hasInstance](instance){
1320
return interfaces.some( interfaceDef => {
1421
if(interfaceDef instanceof InterfaceClass){
@@ -24,6 +31,15 @@ export function Interface(...interfaces){
2431
static getInterfaces(){
2532
return interfaces;
2633
}
34+
static getName(){
35+
return name;
36+
}
37+
static setName(v){
38+
name = v;
39+
}
40+
static toString(){
41+
return name;
42+
}
2743
};
2844
}
2945

0 commit comments

Comments
 (0)