Think about time

When writing an article, write the most exciting part first, because people’s energy is limited, they need to present the best content first to arouse the desire to continue to watch, just like the video of Douyin, the highlight of the video will receive more likes in the first few seconds

Learn about LXGW WenKai/Xia Fan WenKai through Effie, very beautiful, recommended 👍

Want to learn a language? Say it like you’re playing a video game. (Using an interesting story to make you want to read more, public speaking really is a science.)

  1. English is now a tool for results: only 4% of English conversations are between native speakers and native speakers
  2. When you speak English, you should not judge yourself whether you are right or wrong, or whether you are good or bad. Instead, you should focus on whether you can achieve the result that makes the other person understand you

AI is now very powerful, in translation, speech recognition, image recognition has many applications, can understand the simple basic principles

Best views

  1. Colors.js and faker.js are vandalized by open source authors
  2. The Node Util module provides useful utility functions
  3. Null and undefined

Read the article

Open source software with downloads as large as Vue was vandalized by the author, and thousands of apps were affected

content

Colors.js and faker.js have been sabotaged by open source authors who believe that they will no longer “work for free” to support the commercial giants and will either fork projects or compensate open source developers with “six-figure” salaries per year.

The faker.js README was changed to “What happened to Aaron Swartz?” The words.

Swartz is a brilliant developer who helped build Creative Commons, RSS, and Reddit. His contributions have had a profound impact on almost all Web developers. Swartz committed suicide in 2013 at the age of 26 during a legal dispute.

To make the information freely accessible to all, the hacktivists downloaded millions of journal articles from the JSTOR database, the Massachusetts Institute of Technology’s campus network. He allegedly did so by rotating his IP and MAC addresses repeatedly to circumvent technical blocking schemes put in place by the university and JSTOR. But Swartz faces charges under the Computer Fraud and Abuse Act, which carries a possible sentence of up to 35 years in prison.

Open source authors’ GitHub accounts have also been disabled (GitHub can also disable your account, so make sure you back it up yourself)

Marak’s aggressive behavior comes on the heels of a recent high-profile Log4j bug. As a heavyweight open source library, Log4j is widely used in a wide variety of Java applications developed by different enterprises and commercial entities. The exposure of the Log4shell bug caused more and more Cves, and many open source maintainers had to help fix these free projects for free during their vacation.

thinking

Complaints about pay are understandable, but the vandalism is extreme (I always thought open source authors who could write libraries like this would have no money problems 😐).

How useful is the util module built into Node.js?

content

Util /types will help you determine the type

const types = require('util/types');

types.isDate(new Date()); // true
types.isPromise(new Promise(() = > {})); // true
types.isArrayBuffer(new ArrayBuffer(16)); // true
Copy the code

Is the deep comparison exactly equal isDeepStrictEqual

const util = require('util');

const val1 = { name: 'shenfq'.x: 1 };
const val2 = { x: 1.name: 'shenfq' };

console.log('val1 === val2', val1 === val2); // false
console.log('isDeepStrictEqual', util.isDeepStrictEqual(val1, val2)); // true
Copy the code

Early Node apis were Error First, but now they are mostly promise based. How do you convert an Error First API into a Promise API?

Using promisify

const fs = require('fs');
const util = require('util');

const readFile = util.promisify(fs.readFile);
readFile('./a.ts', { encoding: 'utf-8' })
    .then(text= > console.log(text))
    .catch(error= > console.error(error));
Copy the code

Incidentally: Callbackify can change the Promise style to Error First

Node 10 introduces Promises to make it easier to use

const fs = require('fs').promises;
fs.readFile('./a.ts', { encoding: 'utf-8' })
    .then(text= > console.log(text))
    .catch(error= > console.error(error));
Copy the code

Util. Debug can achieve the effect similar to the debug package, and the output information is convenient for debugging

Util. Format Formats output strings

Util. Inspect controls which objects to output

thinking

The Error First style is very useful for converting promises to async mode development (before I knew promisify, I wanted to write my own promisify, but I gave it up because it was too difficult 😂, see how the source code works)

Can I get this util in the browser?

Delve deeper: What’s the difference between null and undefined?

content

Undefined: this variable is undefined, null: this variable is defined, but represents the null value (usually represents the initial value of an object, similar to the initial value of a string string)

Several different forms of presentation are then demonstrated and the reasons are explained

typeof null; // 'object' for historical reasons
typeof undefined; // 'undefined'

Object.prototype.toString.call(null); // '[object Null]'
/ / Object. The prototype. The toString () method is the archetype of the Object
By default, the internal property of the current object [[Class]] is returned in the form [object Xxx], where Xxx is the type of the object.
Object.prototype.toString.call(undefined); // '[object Undefined]'

null= =undefined; // true
// Not because of implicit conversions, but because ECMA states in section 11.9.3 that:
// If x is null and y is undefined, return true.
// If x is undefined and y is null, return true.

let a = undefined + 1; // NaN
let b = null + 1; / / 1
Number(undefined); // NaN
Number(null); / / 0

JSON.stringify({ a: undefined }); / / '{}'
JSON.stringify({ b: null }); // '{b: null}'
JSON.stringify({ a: undefined.b: null }); // '{b: null}'
// JSON will delete the key corresponding to undefined. This is JSON's own conversion principle.

function test(n) {
    let undefined = 'test';
    return n === undefined;
}
test(); // false
test(undefined); // false
test('test'); // ture
let undefined = 'test'; // Uncaught SyntaxError: Identifier 'undefined' has already been declared
// null is a keyword, and undefined is a global variable. Local variables can be overridden, but must not be
// If you want to feel that undefined is true, use void 0, because void plus any expression returns undefined
Copy the code

Everyone has their own rules on whether to use undefined or null, but try to be consistent within the team

thinking

Local undefined can also be reassigned, which is unexpected, so void 0 is safer

Use the Chrome Devtools Memory tool to prove how string Memory is allocated

content

Give a simple and effective example. Use the Allocation instrumentation on timeline mode in Memory to verify the Memory Allocation mode of string by applying strings at different times.

thinking

“Guang “@756367 at indicates the memory address

We see the location of the memory address, but how do we prove that the memory address is a stack, heap, or constant pool? 🤔

2022-01-07 ~ 2022-01-13 (Issue 5)