admin管理员组

文章数量:1302181

I have seen lot of examples in Firefox addon-sdk which uses the below style when declaring a variable.

var { Hotkey } = require("sdk/hotkeys");

What difference it makes with var { Hotkey } than using var HotKey? Why the extra flower brackets are used?

I have seen lot of examples in Firefox addon-sdk which uses the below style when declaring a variable.

var { Hotkey } = require("sdk/hotkeys");

What difference it makes with var { Hotkey } than using var HotKey? Why the extra flower brackets are used?

Share Improve this question asked Feb 13, 2013 at 7:14 Navaneeth K NNavaneeth K N 15.5k38 gold badges132 silver badges189 bronze badges 1
  • Don't know myself, but this might have some information for you: stackoverflow./questions/4445496/… – CodeMoose Commented Feb 13, 2013 at 7:19
Add a ment  | 

1 Answer 1

Reset to default 14

This is destructuring assignment.

var {Hotkey} = require('sdk/hotkeys');

is equivalent to:

var Hotkey = require('sdk/hotkeys').Hotkey;

See also the harmony:destructuring proposal, which includes the following examples:

// object destructuring
var { op: a, lhs: b, rhs: c } = getASTNode()

// digging deeper into an object
var { op: a, lhs: { op: b }, rhs: c } = getASTNode()

本文标签: firefoxWhy use varVariableName require(3939) in javascriptStack Overflow