User Tools

Site Tools


javascript:index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
javascript:index [2022/12/02 21:02] – external edit 127.0.0.1javascript:index [2024/10/05 17:00] (current) – removed rlunaro
Line 1: Line 1:
-====== Javascript ====== 
- 
-===== Class example in node.js ===== 
- 
-<code javascript> 
-/** 
- * 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; 
-</code> 
- 
- 
-For use it is as easy as:  
- 
-<code javascript> 
-const Backend = require('./backend'); 
- 
-let b1 = new Backend(); 
- 
-b1.doSomething(); 
-Backend.otherMethod(); 
- 
-</code> 
- 
  
javascript/index.1670014949.txt.gz · Last modified: 2022/12/02 21:02 by 127.0.0.1