理解模块需要Javascript的语法

时间:2017-10-05 12:50:48

标签: javascript ecmascript-6

我最近遇到过这行代码。

Data: { Selectors }

有人可以告诉我{Selectors}在这段代码中做了什么吗?我知道它在我的代码库中导入了一些模块,只是对import部分感到困惑。

另外,如果我想用import Bar from "some-module"语法编写它,那么它的等效代码是什么?

例如:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) at sun.security.ssl.Handshaker.processLoop(Unknown Source) at sun.security.ssl.Handshaker.process_record(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source) at sun.security.ssl.AppOutputStream.write(Unknown Source) at java.io.BufferedOutputStream.flushBuffer(Unknown Source) at java.io.BufferedOutputStream.flush(Unknown Source)

1 个答案:

答案 0 :(得分:2)

它与模块没有任何关系(导入或需要的语法相同:import {Bar} from "some-module"),它只是创建两个变量的destructuring assignment http://es6-features.org/#ObjectMatchingDeepMatching 1}}和Bar

这是另一个示例以及许多其他ES6功能{{3}}



Selector




上述内容与

相同
    const obj = {Bar: 1, Data: { Selectors: [1,2]}};
    const { Bar, Data: { Selectors } } = obj;
    // This is another ES6 feature, same as saying
    // console.log({Bar: Bar})
    console.log({Bar});
    console.log({Selectors});