//sensor1.js
var distance = 0
function getDistance(){ return distance }

module.exports = { getDistance : getDistance}


in your server.js

var sensor1 = require('./sensor1.js')
sensor1.getDistance()


don't call it class, it is not a class. even with the constructor function. 
we have a name for it, it's module. modules have scope: everything defined 
in them with var of function statement is private, everything you 
add/assign to module.exports object is public. all functions defined in the 
module share the module scope and cann read/manipulate things in this scope 
(pretty much like class scope)
if you need more than one instance of your module, export a constructor or 
factory function and wrap the instance vars in it:

//sensor1_notSingleton.js
function Cons(){
  this.distance = 0
}
Cons.prototype.getDistance = function getDistance(){ return this.distance }

module.exports = Cons

Am Donnerstag, 27. März 2014 10:53:46 UTC+1 schrieb fm3391:
>
> *contents of "sensor1_class.js"*
>
> var Sensor1 = function(){
> this.distance = 0;
>  getDistance: function (){
> return distance;
> }
>
> };
>
> module.exports = Sensor1;
>
>
>
>
> *partial contents of "server.js"*
>
> var sensor1 = require('./sensor1_class');
>
> console.log(sensor1.getDistance()); <--- Here is where I am having the 
> trouble, I just want to call a method of object "Sensor1" that returns the 
> property "distance"
>
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to