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}!`;
相关推荐
FYKJ_20102 小时前
springboot贫困生认定管理系统59009-计算机毕业设计、课程设计
java·javascript·vue.js·spring boot·后端·django·课程设计
kyriewen2 小时前
我测了 5 种关页上报,两种老写法一条都没发出去
前端·javascript·程序员
不一样的少年_4 小时前
受够了当人肉传话筒:我把这 9 个 Agent 塞进了同一个聊天框
前端·agent·ai编程
狗头大军之江苏分军6 小时前
《潮水漫过十七岁》 加一个蛋,顺便说一下我解放了
前端·后端
Captaincc6 小时前
掘金AI用量迎来重大更新!全新AI用量
前端·后端
天若有情6737 小时前
开源|纯前端·条码&二维码在线生成器,支持拖拽缩放、复制生成码图片
前端·javascript·开源·html·二维码·条形码
map_vis_3d9 小时前
控制百度地图视野:setCenter、setZoom、panTo、flyTo 和 setViewport
前端·javascript·地图·百度地图
map_vis_3d9 小时前
百度地图 3D 视角:倾斜 tilt 与旋转 heading
前端·webgl·地图·百度地图·三维
Hilaku9 小时前
前端到底要不要写单元测试?
前端·javascript·程序员
ikoala10 小时前
每个独立开发者上线前,务必用这个skill做一次安全漏洞自查
前端·javascript·后端