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}!`;
相关推荐
学掌门8 分钟前
JavaScript:为什么命名参数比位置参数更好
开发语言·javascript·ecmascript
JoneBB8 分钟前
ABAP上传EXCEL模板并将内表内容存到两个sheet中
java·前端·数据库
usdoc文档预览22 分钟前
国产化踩坑:Vue3 / React / 小程序如何免插件实现 OFD 及复杂 Office 文档同屏预览
前端·javascript·react.js·小程序·pdf·word·office文件在线预览
坏小虎25 分钟前
【聊天列表组件选型建议】FlashList、FlatList、LegendList三种列表组件
javascript·react native·react.js
UXbot29 分钟前
评审前2小时完成页面布局:前端AI工具快速出图工作流
前端·人工智能·交互·产品经理·web app·ui设计
懂懂tty38 分钟前
Vue3 手写响应式原理
前端·vue.js
鹏程十八少38 分钟前
Android 无障碍服务失效,一次AccessibilityService“离奇死亡”的完整破案实录
前端·后端·面试
weixin_511875331 小时前
【无标题】
前端
木斯佳1 小时前
前端八股文面经大全:质谱华章前端一面(2026-05-14)·面经深度解析
前端·面试·面经
水煮白菜王1 小时前
JSONEditor 使用指南
前端·javascript·chrome·json