I'm doing some FF add-on development and I'm seeing syntax like this:
var {Cc, Ci} = require('chrome');
Just curious what that syntax is and if it's special to FF development or something else.
It is an open-source and cross-platform language. JavaScript syntax refers to the set of rules that determines how JavaScript programs are constructed: // Variable declaration var c, d, e; // Assign value to the variable c = 5; // Computer value of variables d = c; e = c/d;
In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.
The computation is called an evaluation. The values can be of various types, such as numbers and strings. JavaScript keywords are used to identify actions to be performed. In these examples, using var or let will produce the same result. You will learn more about var and let later in this tutorial. Not all JavaScript statements are "executed".
Not all JavaScript statements are "executed". Code after double slashes // or between /* and */ is treated as a comment. You will learn more about comments in a later chapter. Identifiers are names. In JavaScript, identifiers are used to name variables (and keywords, and functions, and labels).
This is called destructuring assignment. It is a feature of JavaScript 1.7, where in this context "JavaScript" refers to Mozilla's specific extensions to the ECMAScript standard.
It is slated for inclusion in the next version of JavaScript.
The equivalent ECMAScript 5 code would be
var __temp = require('chrome'); var Cc = __temp.Cc; var Ci = __temp.Ci;
See Domenic's answer as to what the syntax is which is called a destructuring assignment. The answer that follows is why this is needed for FF add-on development.
There's a discussion on what this is and why it is needed at http://groups.google.com/group/mozilla-labs-jetpack/browse_thread/thread/d288b79903b5b434.
Short answer is yes, it's specific for Firefox add-on development. The relevant documentation can be found at https://addons.mozilla.org/en-US/developers/docs/sdk/1.3/dev-guide/module-development/chrome.html.
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