your replace the existing prototype object with a new one (and loose
the previous one).
When you do not want to repeat the assignment 'explicitly', you can use the following code:
var obj;
for ( propName in (obj =
{ getSensorAddress: function() {.....}
, getSensorType: function() {.....}
, .....
})) Sensor.prototype[propName] = obj[propName];
This is mixing one object's properties into another one.
Btw, this 'mixing' shows you how you can dynamically access value and function properties of an object. Assume you have an object with two function properties (methods) f1 and f2.
var obj = { f1: function(){.....}, f2:function(){.....} };
The following three lines invoke all f2 method of obj object, of which the last one makes is dynamically by the fx variable:
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.
@d0773d, when you say:
you add a function property to the prototype object of Sensor.
When you say:
your replace the existing prototype object with a new one (and loose
the previous one).
When you do not want to repeat the assignment 'explicitly', you can use the following code:
This is mixing one object's properties into another one.
Btw, this 'mixing' shows you how you can dynamically access value and function properties of an object. Assume you have an object with two function properties (methods) f1 and f2.
The following three lines invoke all f2 method of obj object, of which the last one makes is dynamically by the fx variable: