Browse Source

:memo: Rewrite docs on destructuring assignment [ci skip]

Steve Kinney 9 years ago
parent
commit
afe0296e0f
1 changed files with 22 additions and 11 deletions
  1. 22 11
      docs/api/synopsis.md

+ 22 - 11
docs/api/synopsis.md

@@ -19,13 +19,11 @@ scripts to be able to use those modules.
 The main process script is just like a normal Node.js script:
 
 ```javascript
-const electron = require('electron');
-const app = electron.app;
-const BrowserWindow = electron.BrowserWindow;
+const { app, BrowserWindow } = require('electron');
 
-var window = null;
+let window = null;
 
-app.on('ready', function() {
+app.on('ready', () => {
   window = new BrowserWindow({width: 800, height: 600});
   window.loadURL('https://github.com');
 });
@@ -39,7 +37,7 @@ extra ability to use node modules:
 <html>
 <body>
 <script>
-  const remote = require('electron').remote;
+  const { remote } = require('electron');
   console.log(remote.app.getVersion());
 </script>
 </body>
@@ -50,16 +48,29 @@ To run your app, read [Run your app](../tutorial/quick-start.md#run-your-app).
 
 ## Destructuring assignment
 
-If you are using CoffeeScript or Babel, you can also use
+As of 0.37, you can use
 [destructuring assignment][destructuring-assignment] to make it easier to use
-built-in modules:
+built-in modules.
+
+```javascript
+const { app, BrowserWindow } = require('electron');
+```
+
+If you need the entire `electron` module, you can require it and then using
+destructuring to access the individual modules from `electron`.
 
 ```javascript
-const {app, BrowserWindow} = require('electron')
+const electron = require('electron');
+const { app, BrowserWindow } = electron;
 ```
 
-However if you are using plain JavaScript, you have to wait until Chrome fully
-supports ES6.
+This is equivalent to the following code:
+
+```javascript
+const electron = require('electron');
+const app = electron.app;
+const BrowserWindow = electron.BrowserWindow;
+```
 
 ## Disable old styles of using built-in modules