所以,我将一个对象传递给ES6函数,我希望 destructure 向下到参数的参数。例如,下面的代码会记录data
的{{1}}道具,但我希望它能记录stuff
things
data
道具stuff
}。所以正确答案会记录[1,2,3,4]
。我知道,根本不会混淆。有人知道这是否可行?
const stuff = {
data: {
things: [1,2,3,4]
}
};
const getThings = ({ data }) => {
console.log(data)
};
getThings(stuff);
答案 0 :(得分:15)
当然,这是如何:
public static void main(String[] args) throws FileNotFoundException {
String treeString = "(ROOT (S (NP (NNP John)) (VP (VBZ eats) (NP (NN pizza))) (. .)))";
Tree tree = Tree.valueOf(treeString);
SemanticGraph graph = SemanticGraphFactory.generateUncollapsedDependencies(tree);
//add lemmata
Morphology morphology = new Morphology();
for (IndexedWord node : graph.vertexSet()) {
String lemma = morphology.lemma(node.word(), node.tag());
node.setLemma(lemma);
}
System.err.println(graph);
SemgrexPattern semgrex = SemgrexPattern.compile("{}=A <<dobj=reln {lemma:/eat/}=B");
SemgrexMatcher matcher = semgrex.matcher(graph);
while (matcher.find()) {
System.err.println(matcher.getNode("A") + " <<dobj " + matcher.getNode("B"));
}
}
答案 1 :(得分:4)
正如我正确理解你的那样,正确答案是:
const getThings = ({ data: { things } }) => {
console.log(things)
};