自己用react开发了一张Es6的学习页面(持续更新系列)



代码块:

java 复制代码
import React from 'react';
import './Es6Review.css';

const Es6Review: React.FC = () => {
    return (
        <div className="container">
            <div className="header">
                <h1>ES6 知识点复习</h1>
                <h2>重要特性及应用</h2>
            </div>
            <div className="section">
                <h3 className="title">1. 箭头函数</h3>
                <p className="paragraph">箭头函数提供了一种更简洁的函数书写方式,并且不绑定自己的 this 值。</p>
                <pre className="codeBlock">
                    {`const add = (a, b) => a + b;`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">2. 模板字符串</h3>
                <p className="paragraph">模板字符串允许嵌入表达式,使用反引号(\`)包裹。</p>
                <pre className="codeBlock">
                    {`const name = '世界';
console.log(\`你好, \${name}!\`);`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">3. 解构赋值</h3>
                <p className="paragraph">解构赋值可以从数组或对象中提取值。</p>
                <pre className="codeBlock">
                    {`const arr = [1, 2, 3];
const [a, b] = arr; // a = 1, b = 2

const obj = { x: 1, y: 2 };
const { x, y } = obj; // x = 1, y = 2`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">4. Promise</h3>
                <p className="paragraph">Promise 是用于处理异步操作的对象。</p>
                <pre className="codeBlock">
                    {`const fetchData = () => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('数据加载完成');
        }, 1000);
    });
};

fetchData().then(data => console.log(data));`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">5. 类</h3>
                <p className="paragraph">ES6 引入了类的概念,提供了更清晰的面向对象编程方式。</p>
                <pre className="codeBlock">
                    {`class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

    greet() {
        console.log(\`你好,我是 \${this.name},我 \${this.age} 岁。\`);
    }
}

const person = new Person('小明', 25);
person.greet();`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">6. 模块化</h3>
                <p className="paragraph">ES6 支持模块化,可以使用 export 和 import 来管理模块。</p>
                <pre className="codeBlock">
                    {`// module.js
export const PI = 3.14;
export const add = (a, b) => a + b;

// main.js
import { PI, add } from './module';
console.log(PI);
console.log(add(2, 3));`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">7. 扩展运算符</h3>
                <p className="paragraph">扩展运算符(...)可以展开数组或对象。</p>
                <pre className="codeBlock">
                    {`const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = [...arr1, ...arr2]; // [1, 2, 3, 4, 5, 6]

const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const merged = { ...obj1, ...obj2 }; // { a: 1, b: 3, c: 4}`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">8. 默认参数</h3>
                <p className="paragraph">可以为函数参数设置默认值。</p>
                <pre className="codeBlock">
                    {`const multiply = (a, b = 1) => a * b;
console.log(multiply(5)); // 5
console.log(multiply(5, 2)); // 10`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">9. let 和 const</h3>
                <p className="paragraph">let 和 const 用于声明变量,let 具有块级作用域,const 声明常量。</p>
                <pre className="codeBlock">
                    {`let x = 10;
if (true) {
    let x = 20; // 块级作用域
    console.log(x); // 20
}
console.log(x); // 10

const y = 30;
// y = 40; // 错误,常量不能被重新赋值`}
                </pre>
            </div>
            <div className="section">
                <h3 className="title">10. 迭代器和生成器</h3>
                <p className="paragraph">生成器函数可以用来创建迭代器。</p>
                <pre className="codeBlock">
                    {`function* generator() {
    yield 1;
    yield 2;
    yield 3;
}

const gen = generator();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2`}
                </pre>
            </div>
        </div>
    );
};

export default Es6Review;
相关推荐
架构师伯子明5 分钟前
FFmpeg C++学习(一):编译和demo
开发语言·c++·学习
叼烟扛炮18 分钟前
[LangChain] 学习笔记(02):LCEL 链式调用与动态模型配置实战
服务器·开发语言·网络·笔记·学习·langchain
程序员梅雨24 分钟前
【从零开始学习数据仓库 | 第二篇】: 拉链表 & 数仓分层
大数据·数据仓库·学习
一木 之林1 小时前
Dify学习笔记 04 · 检索底座:Embedding、Rerank与向量数据库(第46-54集)
笔记·学习·embedding·dify
芯思路1 小时前
STM32开发学习笔记之十【AI部署】
笔记·stm32·学习
憧憬成为java架构高手的小白2 小时前
langgraph4j学习
学习
CCIE-Yasuo2 小时前
网络安全-学习web开发-列表、标签
前端·学习·web安全
旖旎夜光2 小时前
LeetCode 315: 算右侧小于当前元素的个数(归并排序) —— 题解
c++·学习·算法·leetcode·排序算法
海绵宝宝转agent3 小时前
LeetCodehot100题解
java·笔记·学习·算法·leetcode·深度优先
芒果作者3 小时前
我决定系统学习 Codex,并建立一套自己的知识库
学习