这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit fc3d013

Browse files
author
Michael Wilson
committed
Use let instead of var in examples
1 parent c7ca48d commit fc3d013

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

explainer.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The following are some examples of common MIDI usage in JavaScript.
77
This example shows how to request access to the MIDI system.
88

99
```js
10-
var midi = null; // global MIDIAccess object
10+
let midi = null; // global MIDIAccess object
1111

1212
function onMIDISuccess( midiAccess ) {
1313
console.log( "MIDI ready!" );
@@ -26,7 +26,7 @@ This example shows how to request access to the MIDI system, including the
2626
ability to send and receive System Exclusive messages.
2727

2828
```js
29-
var midi = null; // global MIDIAccess object
29+
let midi = null; // global MIDIAccess object
3030

3131
function onMIDISuccess( midiAccess ) {
3232
console.log( "MIDI ready!" );
@@ -46,15 +46,15 @@ information to the console log, using ES6 for...of notation.
4646

4747
```js
4848
function listInputsAndOutputs( midiAccess ) {
49-
for (var entry of midiAccess.inputs) {
50-
var input = entry[1];
49+
for (let entry of midiAccess.inputs) {
50+
let input = entry[1];
5151
console.log( "Input port [type:'" + input.type + "'] id:'" + input.id +
5252
"' manufacturer:'" + input.manufacturer + "' name:'" + input.name +
5353
"' version:'" + input.version + "'" );
5454
}
5555

56-
for (var entry of midiAccess.outputs) {
57-
var output = entry[1];
56+
for (let entry of midiAccess.outputs) {
57+
let output = entry[1];
5858
console.log( "Output port [type:'" + output.type + "'] id:'" + output.id +
5959
"' manufacturer:'" + output.manufacturer + "' name:'" + output.name +
6060
"' version:'" + output.version + "'" );
@@ -68,8 +68,8 @@ the console log.
6868

6969
```js
7070
function onMIDIMessage( event ) {
71-
var str = "MIDI message received at timestamp " + event.timeStamp + "[" + event.data.length + " bytes]: ";
72-
for (var i=0; i<event.data.length; i++) {
71+
let str = "MIDI message received at timestamp " + event.timeStamp + "[" + event.data.length + " bytes]: ";
72+
for (let i=0; i<event.data.length; i++) {
7373
str += "0x" + event.data[i].toString(16) + " ";
7474
}
7575
console.log( str );
@@ -87,8 +87,8 @@ queues a corresponding note off message for 1 second later.
8787

8888
```js
8989
function sendMiddleC( midiAccess, portID ) {
90-
var noteOnMessage = [0x90, 60, 0x7f]; // note on, middle C, full velocity
91-
var output = midiAccess.outputs.get(portID);
90+
let noteOnMessage = [0x90, 60, 0x7f]; // note on, middle C, full velocity
91+
let output = midiAccess.outputs.get(portID);
9292
output.send( noteOnMessage ); //omitting the timestamp means send immediately.
9393
output.send( [0x80, 60, 0x40], window.performance.now() + 1000.0 ); // Inlined array creation- note off, middle C,
9494
// release velocity = 64, timestamp = now + 1000ms.
@@ -100,8 +100,8 @@ This example loops all input messages on the first input port to the first
100100
output port - including System Exclusive messages.
101101

102102
```js
103-
var midi = null; // global MIDIAccess object
104-
var output = null;
103+
let midi = null; // global MIDIAccess object
104+
let output = null;
105105

106106
function echoMIDIMessage( event ) {
107107
if (output) {
@@ -111,7 +111,7 @@ function echoMIDIMessage( event ) {
111111

112112
function onMIDISuccess( midiAccess ) {
113113
console.log( "MIDI ready!" );
114-
var input = midiAccess.inputs.entries().next();
114+
let input = midiAccess.inputs.entries().next();
115115
if (input)
116116
input.onmidimessage = echoMIDIMessage;
117117
output = midiAccess.outputs.values().next().value;
@@ -135,14 +135,14 @@ are not. This sample is also hosted on <a href=
135135
"http://webaudiodemos.appspot.com/monosynth/index.html">webaudiodemos.appspot.com</a>.
136136

137137
```js
138-
var context=null; // the Web Audio "context" object
139-
var midiAccess=null; // the MIDIAccess object.
140-
var oscillator=null; // the single oscillator
141-
var envelope=null; // the envelope for the single oscillator
142-
var attack=0.05; // attack speed
143-
var release=0.05; // release speed
144-
var portamento=0.05; // portamento/glide speed
145-
var activeNotes = []; // the stack of actively-pressed keys
138+
let context=null; // the Web Audio "context" object
139+
let midiAccess=null; // the MIDIAccess object.
140+
let oscillator=null; // the single oscillator
141+
let envelope=null; // the envelope for the single oscillator
142+
let attack=0.05; // attack speed
143+
let release=0.05; // release speed
144+
let portamento=0.05; // portamento/glide speed
145+
let activeNotes = []; // the stack of actively-pressed keys
146146

147147
window.addEventListener('load', function() {
148148
// patch up prefixes
@@ -167,9 +167,9 @@ window.addEventListener('load', function() {
167167
function onMIDIInit(midi) {
168168
midiAccess = midi;
169169

170-
var haveAtLeastOneDevice=false;
171-
var inputs=midiAccess.inputs.values();
172-
for ( var input = inputs.next(); input &amp;& !input.done; input = inputs.next()) {
170+
let haveAtLeastOneDevice=false;
171+
let inputs=midiAccess.inputs.values();
172+
for ( let input = inputs.next(); input &amp;& !input.done; input = inputs.next()) {
173173
input.value.onmidimessage = MIDIMessageEventHandler;
174174
haveAtLeastOneDevice = true;
175175
}
@@ -209,7 +209,7 @@ function noteOn(noteNumber) {
209209
}
210210

211211
function noteOff(noteNumber) {
212-
var position = activeNotes.indexOf(noteNumber);
212+
let position = activeNotes.indexOf(noteNumber);
213213
if (position!=-1) {
214214
activeNotes.splice(position,1);
215215
}

index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,18 @@ <h3 id="MIDIInputMap">
455455
ports. This enables:
456456
</p>
457457
<pre class="example"> // to tell how many entries there are:
458-
var numberOfMIDIInputs = inputs.size;
458+
let numberOfMIDIInputs = inputs.size;
459459

460460
// add each of the ports to a &lt;select&gt; box
461461
inputs.forEach( function( port, key ) {
462-
var opt = document.createElement("option");
462+
let opt = document.createElement("option");
463463
opt.text = port.name;
464464
document.getElementById("inputportselector").add(opt);
465465
});
466466

467467
// or you could express in ECMAScript 6 as:
468468
for (let input of inputs.values()) {
469-
var opt = document.createElement("option");
469+
let opt = document.createElement("option");
470470
opt.text = input.name;
471471
document.getElementById("inputportselector").add(opt);
472472
}</pre>
@@ -489,18 +489,18 @@ <h3 id="MIDIOutputMap">
489489
output ports=]. This enables:
490490
</p>
491491
<pre class="example"> // to tell how many entries there are:
492-
var numberOfMIDIOutputs = outputs.size;
492+
let numberOfMIDIOutputs = outputs.size;
493493

494494
// add each of the ports to a &lt;select&gt; box
495495
outputs.forEach( function( port, key ) {
496-
var opt = document.createElement("option");
496+
let opt = document.createElement("option");
497497
opt.text = port.name;
498498
document.getElementById("outputportselector").add(opt);
499499
});
500500

501501
// or you could express in ECMAScript 6 as:
502502
for (let output of outputs.values()) {
503-
var opt = document.createElement("option");
503+
let opt = document.createElement("option");
504504
opt.text = output.name;
505505
document.getElementById("outputportselector").add(opt);
506506
}</pre>

0 commit comments

Comments
 (0)