Skip to content

Instantly share code, notes, and snippets.

@jgautier
jgautier / node-firmata-attempt.js
Created July 6, 2011 23:14 — forked from karlwestin/node-firmata-attempt.js
My short node-js-firmata attempt
// 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
});
@jgautier
jgautier / let.js
Created May 24, 2011 04:55
sample code for let
function letX(){
var x = 0;
if(true){
let x = 1;
//1
console.log(x);
}
//0
console.log(x);
}
@jgautier
jgautier / apply.js
Created May 23, 2011 03:59
Javascript Scoping
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){
@jgautier
jgautier / __proto__.js
Created March 9, 2011 06:04
Settign the .prototype property
//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();
SerialPort = require('serialport').SerialPort
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;
};
};