Create getter and setter module in NodeJS

var number, origin, destination;

exports.setNumber = function (num) {
number = num;
};

exports.setOrigin = function (o) {
origin = o;
};

exports.setDestination = function (d) {
destination = d;
};

exports.getInfo = function () {
return {
number      : number,
origin      : origin,
destination : destination
};
};

==============================
user in app.js


var flight = require('./flight');

flight.setOrigin('Kensington');
flight.setDestination('London');
flight.setNumber(356);

console.log(flight.getInfo());

No comments:

Post a Comment