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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -