Javascript Note
- About NodeJS see Node Note
- @2021-12-24: Renamed ES6 Note to JS Note since ES next, es 2021, es2022
Overloading a built-in Class#
- @2021-09-24
- Classes are not just syntactic sugar for the prototypal pattern
- JavaScript has no user-defined operator overloading
- But the value get by
valueOf()can be overloaded like this
Class inheritance#
- @2021-10-04
class B extends Aneeds to callsuper()and the return value(constructed class instance) ofA.constructor()is stored inB.this.
Online sandbox#
- @2021-10-08
- Stackblitz vs CodeSandbox
- Stackblitz is much faster but the package can only be imported from its own NPM system.
- CodeSandbox can add preview packages
Object.assign()#
- @2021-10-21
- will change first var.
Array Trap#
- @2021-10-21
- Trap:
arr.entries()andarr.forEach()takes different(ind,val)order:[ind,val] in arr.entries()andarr.forEach((val,ind)=>null)
BigInt#
- @2021-10-21
- Is a primitive JS type
- Has literal expression (
BigInt(5) === 5n;) - Division will automatic floor.
String Template#
- @2021-12-16
- [ ] TODO : ruanyifeng
1 2 3 4 5 6 7 | |
Typing and JSDocs#
- @2021-12-21
- Object arguments with param: Stack Overflow How to describe "object" arguments in jsdoc?, Official web @param.
- TS
?optional operator is=in jsdoc. - Empty property type check: Property ... does not exist on type 'IntrinsicAttributes & ...': to solve JSX error , use
|{}.
Tagged template#
- @2021-12-18
- Tagged template
- Chinese version, Ruanyifeng, Tagged template
Proxy#
- @2021-12-28
- How to use javascript proxy for nested objects : Use two proxies
- @2021-01-03
array.pushwill not trigger "set" method of proxy- Example on Gist
Throw Error#
- @2022-01-03
throw Error('msg')andthrow new Error('msg')does the same thing. BecauseError('msg')andnew Error('msg')are the same thing.- Full answer on Stack Overflow
Import and Export#
- @2022-01-10
import '/modules/my-module.js'will Import a module for its side effects only
Import raw string#
- @2022-01-10
- Out of expectation,
const fs=require('fs')works. - These won't work
Why folder-level index.js#
- @2022-01-11
- It's just for importing and exporting easier. The name is confusing, we can make it
asset/asset.tstoo. The problem is not theindex.tses. Rather a bad pattern on using them. We shouldn’t write any code inindex.ts, instead only export and import, and maybe some typing definition. - origin
Async iterator to array#
- @2022-01-13
- From How can I convert an async iterator to an array?
1 2 3 4 5 | |