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}!`;
相关推荐
rgeshfgreh17 分钟前
Spring事务传播机制深度解析
java·前端·数据库
Hilaku1 小时前
我用 Gemini 3 Pro 手搓了一个并发邮件群发神器(附源码)
前端·javascript·github
IT_陈寒1 小时前
Java性能调优实战:5个被低估却提升30%效率的JVM参数
前端·人工智能·后端
快手技术1 小时前
AAAI 2026|全面发力!快手斩获 3 篇 Oral,12 篇论文入选!
前端·后端·算法
颜酱1 小时前
前端算法必备:滑动窗口从入门到很熟练(最长/最短/计数三大类型)
前端·后端·算法
全栈前端老曹1 小时前
【包管理】npm init 项目名后底层发生了什么的完整逻辑
前端·javascript·npm·node.js·json·包管理·底层原理
HHHHHY1 小时前
mathjs简单实现一个数学计算公式及校验组件
前端·javascript·vue.js
boooooooom1 小时前
Vue3 provide/inject 跨层级通信:最佳实践与避坑指南
前端·vue.js
一颗烂土豆1 小时前
Vue 3 + Three.js 打造轻量级 3D 图表库 —— chart3
前端·vue.js·数据可视化
青莲8431 小时前
Android 动画机制完整详解
android·前端·面试