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?
In JavaScript, variables are used to hold a value. It can hold any value, from primitives to objects.
Risk managers use VaR to measure and control the level of risk exposure. One can apply VaR calculations to specific positions or whole portfolios or use them to measure firm-wide risk exposure.
In Javascript, it doesn't matter how many times you use the keyword “var”. If it's the same name in the same function, you are pointing to the same variable. This function scope can be a source of a lot of bugs.
Redeclaring a variable is useful in situations where it cannot be known if the variable has already been defined. By redeclaring a variable conditionally, as Google Analytics tracking code does, it allows for a variable to safely originate from more than one place.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With