Ho visto molti esempi in Firefox addon-sdk che usa lo stile sottostante quando si dichiara una variabile.
var { Hotkey } = require("sdk/hotkeys");
Che differenza fa con var { Hotkey }
che usare var HotKey
? Perché vengono utilizzate le parentesi di fiore in più?
risposte:
14 per risposta № 1Questo è incarico destrutturante.
var {Hotkey} = require("sdk/hotkeys");
è equivalente a:
var Hotkey = require("sdk/hotkeys").Hotkey;
Vedi anche il l'armonia: destrutturazione proposta, che include i seguenti esempi:
// object destructuring
var { op: a, lhs: b, rhs: c } = getASTNode()
// digging deeper into an object
var { op: a, lhs: { op: b }, rhs: c } = getASTNode()