2013-03-05 110 views
0

我正在使用Esprima解析器,它輸出一個AST格式,它與Mozilla Spider Monkey Parser API兼容。「默認值」包含什麼?

Mozilla Docs,它指定Function節點:

interface Function <: Node { 
    id: Identifier | null; 
    params: [ Pattern ]; 
    defaults: [ Expression ]; 
    rest: Identifier | null; 
    body: BlockStatement | Expression; 
    generator: boolean; 
    expression: boolean; 
} 

會是什麼defaults屬性包含哪些內容?它總是顯示爲一個空數組。

回答

0

默認的Mozilla JS AST包含ES6默認參數值。

例如,

function t(i = 20) { } 

defaults will be [{ type: 'Literal', value: 20 }]. 

因爲它是基於ES6草案,Esprima主分支不承認它。