自己用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;
相关推荐
FrontAI8 小时前
Next.js从入门到实战保姆级教程:环境配置与项目初始化
react.js·typescript·学习方法
九英里路8 小时前
OS学习之路——动静态库制作与原理
linux·学习·操作系统·unix·进程·编译·动静态库
red_redemption8 小时前
自由学习记录(160)
学习
南無忘码至尊8 小时前
Unity学习90天-第2天-认识Unity生命周期函数并用 Update 控制物体移动,FixedUpdate 控制物理
学习·unity·游戏引擎
报错小能手9 小时前
ios开发方向——swift错误处理:do/try/catch、Result、throws
开发语言·学习·ios·swift
LX567779 小时前
传统销售如何系统学习成为AI智能销售顾问?认证指南
人工智能·学习
做cv的小昊9 小时前
【TJU】应用统计学——第五周作业(3.1 假设检验的基本思想、3.2 单个正态总体参数的假设检验)
学习·线性代数·机器学习·数学建模·矩阵·概率论·tju
格鸰爱童话10 小时前
向AI学习项目技能(六)
java·人工智能·spring boot·python·学习
H_老邪10 小时前
spring boot 学习之路-1.0
spring boot·后端·学习
用户31532477954510 小时前
React19项目中 FormEdit / FormEditModal 组件封装设计说明
前端·react.js