https://developer.mozilla.org/zh-CN/docs/Web/JavaScript

类型与运算符

类型

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators

image.png
image.png

特殊的 undefined, NaN, Infinity, null

String

Array

Map

JSON

  • JSON.parse()

    Parse the string text as JSON, optionally transform the produced value and its properties, and return the value

  • JSON.stringify()

    Return a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manne

Number

i.e. Number(‘123’)

parseInt(),parseFloat()

Math

Date

RegExp

Proxy

Reflect

变量、作用域、判断与循环

https://developer.mozilla.org/zh-CN/docs/Learn/JavaScript/Firststeps/Variables#var%E4%B8%8Elet%E7%9A%84%E5%8C%BA%E5%88%AB (留意变量提升问题) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#description (留意 TDZ 问题) https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Loops_and_iteration

  1. var
  1. //Just like const the let does not create properties of the window object when declared globally (in the top-most scope)
  2. let x = 1;
  3. if (x === 1) {
  4. let x = 2;
  5. console.log(x);
  6. // expected output: 2
  7. }
  8. console.log(x);
  9. // expected output: 1
  1. //This declaration creates a constant whose scope can be either global or local to the block in which it is declared. Global constants do not become properties of the window object, unlike var variables.
  2. const number = 42;
  3. try {
  4. number = 99;
  5. } catch (err) {
  6. console.log(err);
  7. // expected output: TypeError: invalid assignment to const `number'
  8. // Note - error messages will vary depending on browser
  9. }
  10. console.log(number);
  11. // expected output: 42

if (...) {...} else {...}
switch (...) { case (): ... case (): ...}
for (var ... ; ...; ...;) {...}

  1. var step;
  2. for (step = 0; step < 5; step++) {
  3. // Runs 5 times, with values of step 0 through 4.
  4. console.log('Walking east one step');
  5. }
  1. for (variable in object) {
  2. statements
  3. }
  4. // for...in 循环遍历的结果是数组元素的下标;而 for...of 遍历的结果是元素的值
  5. // 在 python 中,for...in... 与 js 的 for...of...相同
  6. let arr = [3, 5, 7];
  7. arr.foo = "hello";
  8. for (let i in arr) {
  9. console.log(i); // 输出 "0", "1", "2", "foo"
  10. }
  11. for (let i of arr) {
  12. console.log(i); // 输出 "3", "5", "7"
  13. }

生成器与迭代器

函数与表达式

function name() {}, 匿名函数 (), 箭头函数 () => {}

  1. var json = JSON.parse(pm.request.body.raw);
  2. setTimeout(() => {
  3. pm.environment.unset("schema_name");
  4. pm.environment.set("schema_name", json.Name);
  5. console.log('schema_name was set successfully')
  6. console.log("schema_name:" + pm.environment.get('schema_name'))
  7. }, 3000)
  1. function random(number) {
  2. return Math.floor(Math.random()*number);
  3. }
  1. function generateRdStr() {
  2. var text = "";
  3. var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  4. for (var i = 0; i < 10; i++)
  5. text += possible.charAt(Math.floor(Math.random() * possible.length));
  6. return text;
  7. }
  1. Date.parse(new Date())
  1. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript#numbers
  2. parseInt('12'); // 12
  3. var num = 1; num.toString()
  1. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

异常

try{...} catch (e) {...} finally {...}

并发模型与事件循环

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/EventLoop

async, await

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

  1. function resolveAfter2Seconds(x) {
  2. return new Promise(resolve => {
  3. setTimeout(() => {
  4. resolve(x);
  5. }, 2000);
  6. });
  7. }
  8. async function f1() {
  9. var x = await resolveAfter2Seconds(10);
  10. console.log(x); // 10
  11. }
  12. f1();

promise

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

image.png

  1. const promise1 = new Promise((resolve, reject) => {
  2. setTimeout(() => {
  3. resolve('foo');
  4. }, 300);
  5. });
  6. promise1.then((value) => {
  7. console.log(value);
  8. // expected output: "foo"
  9. });
  10. console.log(promise1);
  11. // expected output: [object Promise]

抽象语法树

https://esprima.org/demo/parse.html#

继承、原型与原型链

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

new

class

extend

instance of

object