You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • @d0773d, when you say:

    Sensor.prototype.getSensorAddress = function() {...};
    

    you add a function property to the prototype object of Sensor.

    When you say:

    Sensor.prototype = { getSensorAddress: function() {.....},..... };
    

    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:

    obj.f2();
    obj["f2"]();
    var fx = "f2"; obj[fx]();
    
About

Avatar for allObjects @allObjects started