Prototyping works fine in Espruino like this:
function a(v){ this.a = v; this.inc = function() {this.a++;}; } function b(v,x){ a.call(this,v); this.b = x; } b.prototype = a; b.prototype.constructor = b; var t = new b(1,5); console.log(t.a,t.b); t.inc(); console.log(t.a,t.b);
I now would like to create something like OneWireDS18_20 using prototype and cannot get it working.
function myOneWire(pin){ OneWire.call(this,pin); } myOneWire.prototype = OneWire; myOneWire.prototype.constructor = myOneWire; var myOW = new myOneWire(D8); console.log(myOW.search());
@JumJum started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Prototyping works fine in Espruino like this:
function a(v){ this.a = v; this.inc = function() {this.a++;}; }
function b(v,x){ a.call(this,v); this.b = x; }
b.prototype = a;
b.prototype.constructor = b;
var t = new b(1,5); console.log(t.a,t.b);
t.inc(); console.log(t.a,t.b);
I now would like to create something like OneWireDS18_20 using prototype and cannot get it working.
function myOneWire(pin){ OneWire.call(this,pin); }
myOneWire.prototype = OneWire;
myOneWire.prototype.constructor = myOneWire;
var myOW = new myOneWire(D8);
console.log(myOW.search());