JavaScript grammar

general grammar

class to packet data

Use class to packet related const variables, with static to define class-level members that belong to the class itself rather than instances of the class, allowing direct access through the class name (e.g.,ApplePacket.CMD) without instantiation.

The key points about static in this context are:

  • Belongs to the class itself, not instances

  • Can be accessed directly through the class name

  • Shared across all uses of the class

  • No need to create an instance with new

javascript 复制代码
const CMD = {
    a: 1,
    b: 2
};
    
class BLEPacket {
    // Constants
    static CMD = {
    a: 1,
    b: 2
    };
...
}

ES6 语法

  1. 扩展运算符 ...
    口诀:三个点,打散数组,逐个放进去
    例子:
javascript 复制代码
  let arr = [1, 2];
  let more = [3, 4];
  arr.push(...more); // arr 变成 [1, 2, 3, 4]
  1. 解构赋值
    口诀:左边是变量,右边是值,一一对应
    例子:
javascript 复制代码
  let [a, b] = [1, 2]; // a=1, b=2
  let {name, age} = {name: 'Tom', age: 18}; // name='Tom', age=18
  1. 箭头函数 =>
    口诀:箭头指向返回值,一行代码不用大括号
    例子:

    let add = (a, b) => a + b;
    let double = x => x * 2;

  2. 模板字符串 - **口诀**:反引号包裹,${变量}插入- **例子**:js
    let name = 'Tom';
    let greeting = Hello, ${name}!;

javascript 复制代码
  let name = 'Tom';
  let greeting = `Hello, ${name}!`;
相关推荐
Da Da 泓1 小时前
五子棋 Web 端测试用例报告
前端·网络·websocket·网络协议·测试用例·项目
zxcvb1532 小时前
远程查看本地文档:一条轻量 Web 文件服务的工程化链路
前端·远程查看文档
niucloud-admin2 小时前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理
java·前端·php
程序员大阳3 小时前
副队长JavaScript教程(50)-DOM:网页开发的起点
javascript·dom·es·节点·概念·document·关系
北岛贰3 小时前
啵啵音乐迎来全新升级!
前端
hkNaruto5 小时前
【AI】基于大模型的AI游戏地图生成、控制方案:AI Native Game Harness 迁移操作手册
前端·人工智能·游戏
IT_陈寒5 小时前
Java序列化踩坑记:对象循环引用让我加班两小时
前端·人工智能·后端
Acro5 小时前
快给macOS 上的Grok Bot换一套皮肤
前端
flash俊杰5 小时前
双引擎 OCR 编排:逐页判定、视觉优先、partial 语义与三层超时
前端
计算机魔术师5 小时前
Reddit 每周被 Google 偷走 100 万次点击,CEO 摊牌了
前端