javascript-1.7

What does curly brackets in the `var { … } = …` statements do?

早过忘川 提交于 2019-12-16 22:22:11
问题 Not sure if this is a Mozilla-specific JS syntax, but I often found variables being declared this way, for example, in add-on SDK docs: var { Hotkey } = require("sdk/hotkeys"); and in various chrome Javascript ( let statement is being used in place of var ), let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; I found it very confusing but I am not being able to find any documentation about both syntax, even on MDN. 回答1: They're both JavaScript 1.7 features. The first one

What does curly brackets in the `var { … } = …` statements do?

寵の児 提交于 2019-11-25 20:49:41
Not sure if this is a Mozilla-specific JS syntax, but I often found variables being declared this way, for example, in add-on SDK docs : var { Hotkey } = require("sdk/hotkeys"); and in various chrome Javascript ( let statement is being used in place of var ), let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; I found it very confusing but I am not being able to find any documentation about both syntax, even on MDN . Blender They're both JavaScript 1.7 features. The first one is block-level variables : let allows you to declare variables, limiting its scope to the block,