User Tools

Site Tools


javascript:index

This is an old revision of the document!


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.1663234149.txt.gz · Last modified: 2022/12/02 22:02 (external edit)