javascript - Node.js classes as modules -


i trying make application more object orientated. want create following class (object):

in file media.js

    //media object var media = function (file, targetdirectory) {     this.file = file;     this.targetdir = targetdirectory;     this.filename = this.getname(); };  media.prototype.isvideo = function () {     return this.file.mimetype.indexof('video') >= 0; }; media.prototype.isaudio = function () {     return this.file.mimetype.indexof('audio') >= 0; }; media.prototype.getname = function () {     return this.file.originalname.substr(0, this.file.originalname.indexof('.')) }; 

i wish use object in serveral places of application im not quite sure how include it. idea or should use modules instead?

you can export media object follows in media.js

module.exports = media; 

then require media.js when need it

const media = require('pathtofile/media.js')  media.isaudio(a, b);  

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -