初始化类的实例,获得

时间:2018-04-13 11:46:53

标签: javascript json typescript

我正在尝试初始化我的类DFA的新实例,但它没有给出我想要的所需答案。

这是我的DFA课程:

class DFA {
    private nodes: { label: string, attributes?: string[] }[]
    private alphabet: any[]
    private edges: (string | string[])[][]

    constructor(
        nodes: { label: string, attributes?: string[] }[],
        alphabet: any[],
        edges: (string | string[])[][],
    ) {
        this.nodes = nodes
        this.alphabet = alphabet
        this.edges = edges
    }
}

以下是我用来创建DFA类的新实例的数据:

const result = { "nodes": [{ "label": "a", "attributes": ["initial"] }, { "label": "b", "attributes": [] }, { "label": "c", "attributes": ["accept"] }], "edges": [["a", "a", ["1"]], ["a", "b", ["0"]], ["b", "a", ["1"]], ["b", "c", ["0"]], ["c", "c", ["0, 1"]]] };

现在我已经定义了DFA类,并且我获得了创建DFA新实例所需的数据,然后按照以下步骤进行:

const Machine = new DFA(result.nodes, getAlphabet(), result.edges);

getAlphabet()功能,无关紧要,如何制作。但是当我console.log(Machine)时,我得到了:

DFA { 
nodes: 
     [ {label: 'a', attributes: [Object] },
       {label: 'b', attributes: [] },
       {label: 'c', attributes: [Object] }, ],
alphabet: ['1', '0'], 
edges: 
     [ ['a', 'a', [Object] ],
       ['a', 'b', [Object] ], 
       ['b', 'a', [Object] ],
       ['b', 'c', [Object] ],
       ['c', 'c', [Object] ] ] 
}

这不是我期望或想要的结果。 我希望我的结果/输出看起来像是:

[ {label: 'a', attributes: [ 'initial' ] },
  {label: 'b', attributes: [] },
  {label: 'c', attributes: [ 'accept' ] }, ]
...
edges: 
     [ ['a', 'a', ['1'] ],
       ['a', 'b', ['0'] ], 
       ['b', 'a', ['1'] ],
       ['b', 'c', ['0'] ],
       ['c', 'c', ['0, 1'] ] ] 

所以有人知道我做错了吗?以及如何解决它?或者我只是误解了什么?

0 个答案:

没有答案