javascript:index
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
javascript:index [2022/12/02 21:02] – external edit 127.0.0.1 | javascript: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(' | ||
- | |||
- | // object constructor | ||
- | function Backend () { | ||
- | |||
- | this.property = 5; | ||
- | console.log(' | ||
- | } | ||
- | |||
- | // object implementation | ||
- | Backend.prototype = { | ||
- | doSomething : function() { | ||
- | console.log(' | ||
- | } | ||
- | } | ||
- | |||
- | // static method | ||
- | Backend.otherMethod = function() { | ||
- | console.log(' | ||
- | } | ||
- | |||
- | module.exports = Backend; | ||
- | </ | ||
- | |||
- | |||
- | For use it is as easy as: | ||
- | |||
- | <code javascript> | ||
- | const Backend = require(' | ||
- | |||
- | let b1 = new Backend(); | ||
- | |||
- | b1.doSomething(); | ||
- | Backend.otherMethod(); | ||
- | |||
- | </ | ||
- | |||
javascript/index.1670014949.txt.gz · Last modified: 2022/12/02 21:02 by 127.0.0.1