自己用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;
相关推荐
辰海Coding5 小时前
MiniSpring框架学习笔记-解决循环依赖的简化IoC容器
笔记·学习
晓梦林5 小时前
cp520靶场学习笔记
android·笔记·学习
心中有国也有家6 小时前
cann-recipes-infer:昇腾 NPU 推理的“菜谱集合”
经验分享·笔记·学习·算法
前端若水6 小时前
会话管理:创建、切换、删除对话历史
前端·人工智能·python·react.js
Upsy-Daisy6 小时前
AI Agent 项目学习笔记(八):Tool Calling 工具调用机制总览
人工智能·笔记·学习
放下华子我只抽RuiKe57 小时前
React 从入门到生产(四):自定义 Hook
前端·javascript·人工智能·深度学习·react.js·自然语言处理·前端框架
LuminousCPP8 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
魔法阵维护师8 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#
_李小白9 小时前
【android opencv学习笔记】Day 17: 目标追踪(MeanShift)
android·opencv·学习
一只机电自动化菜鸟9 小时前
一建机电备考笔记(40) 建筑机电施工—排水管道施工(含考频+题型)
经验分享·笔记·学习·职场和发展·课程设计