This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On Arduino Uno 2.2 | |
// Using Examples > Firmata > StandardFirmata_2_2_forUNO_0_3 | |
var firmata = require("./firmata/lib/firmata"); | |
var board = new firmata.Board("/dev/tty.usbmodem621",function(){ | |
//code for board needs to go here | |
console.log(board); // logs board object, board.pins is empty | |
board.digitalWrite(2, 1); // generates error can't write value to undefined | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function letX(){ | |
var x = 0; | |
if(true){ | |
let x = 1; | |
//1 | |
console.log(x); | |
} | |
//0 | |
console.log(x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Button(text){ | |
this.text = text; | |
} | |
Button.prototype.onClick=function(callback){ | |
//set fake x,y coordinates | |
var x=0,y=0; | |
callback.apply(this,[x,y]); | |
}; | |
var button = new Button('The Button'); | |
button.onClick(function(x,y){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create object with function | |
var Foo=function(){ | |
}; | |
//set the bar method on the prototype | |
Foo.prototype={ | |
bar:function(){ | |
console.log("bar"); | |
} | |
}; | |
var foo=new Foo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SerialPort = require('serialport').SerialPort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addNumber=function(x){ | |
//first class function : a function treated as an object | |
return function(y){ | |
//x is a free variable. (i.e. not a local variable or an argument of this function.) | |
//x is bound to the argument x in lexical environment defined by the addNumber function | |
return x+y; | |
}; | |
}; |
NewerOlder