User Tools

Site Tools


javascript:index

Javascript

Class example in node.js

/**
 * backend.js - helper functions to connect to the backend
 */
 
const axios = require('axios');
 
// object constructor
function Backend () {
 
  this.property = 5;
  console.log('this is the constructor');
}
 
// object implementation
Backend.prototype = {
  doSomething : function() {
    console.log('hello from backend', this );
  }
}
 
// static method
Backend.otherMethod = function() {
  console.log('this is my static method');
}
 
module.exports = Backend;

For use it is as easy as:

const Backend = require('./backend');
 
let b1 = new Backend();
 
b1.doSomething();
Backend.otherMethod();
javascript/index.txt · Last modified: 2022/09/15 11:29 by rlunaro