Prototyping OneWire #184
Unanswered
espruino-discuss
asked this question in
JavaScript
Replies: 1 comment
-
Posted at 2013-12-30 by @gfwilliams The built in functions can't be called using "call", and that is probably causing you issues. I also don't think that prototype.constructor is honoured at the moment (I need to look at the spec to see how it should be used), but I could be wrong there. It's probably best to just instantiate OneWire as a field in the DS18B20 module, like the existing module does. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Posted at 2013-12-30 by JumJum
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());
Beta Was this translation helpful? Give feedback.
All reactions