5,321
edits
(→Map) |
(→Map) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
==Usage== | ==Usage== | ||
For basic dom manipulation, see [https://htmldom.dev/ https://htmldom.dev/]. | |||
===Inputs=== | ===Inputs=== | ||
Line 179: | Line 180: | ||
===Map=== | ===Map=== | ||
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map MDN Map] | ||
[https://www.ecma-international.org/ecma-262/10.0/index.html#sec-map-objects ES2019 (ES10) Map Specification] | |||
This is your typical hashmap. | |||
<syntaxhighlight lang="js"> | <syntaxhighlight lang="js"> | ||
let myMap = new Map(); | let myMap = new Map(); | ||
Line 215: | Line 219: | ||
===Set=== | ===Set=== | ||
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set MDN Set] | |||
<syntaxhighlight lang="js"> | |||
let my_set = new Set(); | |||
// Returns the set itself | |||
my_set.add(key); | |||
my_set.has(key); | |||
my_set.clear(); | |||
// Returns if key has in the set | |||
my_set.delete(key); | |||
</syntaxhighlight> | |||
===WeakMap=== | ===WeakMap=== | ||
Line 234: | Line 253: | ||
==Modules== | ==Modules== | ||
These days, we can use modules for everything. | |||
===Getting Started=== | ===Getting Started=== | ||
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules MDN Guide to Modules]<br> | [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules MDN Guide to Modules]<br> | ||
Example Module | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
// Import three.js as a module. webpack will resolve this. | |||
import * as THREE from 'three'; | |||
// Import MyClass as a module. webpack will resolve this. | |||
import MyClass from "./MyClass.js"; | |||
// Pretend we're writing another class | |||
export default class MyOtherClass { | |||
constructor() {} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||