Tom`s BlogTom`s Blog
Home
文章
分类
标签
最新
Home
文章
分类
标签
最新
node 10backend 11GIT 1Game 1Game option 1WWII 1tag E 2common sense 2css 1html 2javascript 4frontend 4nodejs 1http 2
原生与Fetch的HTTP请求

Date: 6/16/2025Category: frontendTag: http, frontend, javascript

原生请求

// 发起GET请求
const xhr = new XMLHttpRequest;
xhr.open('GET', 'http://127.0.0.1:3000?name=tom&password=123456')
xhr.onload = () => {
    console.log(xhr.status)
    if (xhr.status === 200) {
        console.log(xhr.responseText)
    } else {
        console.log(`Error:${xhr.status}`)
    }
}
xhr.send();
// 发起POST请求
const xhr = new XMLHttpRequest;
xhr.open('POST', 'http://127.0.0.1:3000/post/userInfo');
xhr.setRequestHeader('Content-type', 'application/x-www-formurlencoded');
xhr.onload = () => {
    if (xhr.status = 200) {
        console.log(xhr.responseText);
    } else {
        console.error(`Error:${xhr.statis}`);
    }
};
xhr.send(JSON.stringify({
    name: "12312321",
    email: "131123@qq.com"
}))
原型与面向对象

Date: 6/16/2025Category: frontendTag: http, frontend, javascript

一切皆对象

原型和原型链都是来源于对象而服务于对象的概念,所以我们要先明确一点:

JavaScript中一切引用类型都是对象,对象就是属性的集合。

Array类型、Function类型、Object类型、Date类型、RegExp类型等都是引用类型。

也就是说 数组是对象、函数是对象、正则是对象、对象还是对象。

原型与原型链是什么

JS执行环境+作用域(上下文)

Date: 7/6/2025Category: frontendTag: frontend, backend, common sense, javascript, nodejs

函数

执行环境

  • 执行环境(执行上下文)是JS中非常重要的一个概念。
  • 每个执行环境都有一个与之关联的虚拟对象(执行上下文对象)
  • 执行环境中定义的所有变量和函数都保存在这个执行上下文对象中,供解析器在处理数据时使用。

预处理

  • 将变量和函数作为执行上下文对象的属性放到这个对象上的这个过程,被称为预处理
  • 预处理发生在代码将要执行之前
  • 虽然JS是解释执行的语言,但是在解释执行之前,还是有个预处理的过程
  • 为代码的执行做准备,提前检查出代码中的错误
  • 算是做了一个通篇扫描的过程
  • 这也是之前讲过的变量的声明提升和函数提升的原因
Cookie与Storage

Date: 6/16/2025Category: frontendTag: html, javascript, frontend

Cookie

说明:

cookie由键值对字符串组成, 在设置Cookie时,可以指定以下属性:

对document.cookie 重新赋值即可新增该Cookie, 而不是替换掉整个Cookies 。

注意:如果需要替换某个Cookie, 必须保证Domain与Path一致。其中 Cookie 内容只能包括 Ascii 码字符,所以需要经过一层编码。