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}!`;
相关推荐
hunterandroid7 分钟前
HarmonyOS HUKS 密钥全生命周期实战:生成、轮换与失效处理
前端·华为
damoluomu9 分钟前
SSG 的后台怎么补:Node.js 生态里的三条路(番外二)
javascript·css·typescript·node.js·html
东鹏特饮16 分钟前
贪吃蛇小游戏html
前端·javascript·html
溪语流沙18 分钟前
【每天一个CSS | Day23】边框上有一道光在跑的流光呼吸卡片
前端·css
小马不起床20 分钟前
零基础玩转 FastAPI_10:前端登录、权限与布局
前端·状态模式·fastapi
程序员Sunday27 分钟前
JavaScript 深拷贝和浅拷贝有什么区别?structuredClone 能替代 JSON 拷贝吗?
前端·javascript
ShineWinsu1 小时前
对于CSS:选择器的解析
前端·css·面试·html·web·选择器·网页
m0_587383001 小时前
碰碰好评卡功能落地实战 从需求梳理到上线部署全流程实操指南
java·linux·服务器·前端·javascript·vue.js·人工智能
Pu_Nine_91 小时前
Vue‑Flow 从零入门实战|AI‑Agent 拓扑图开发
前端·javascript·vue.js
keyipatience1 小时前
CSS 学习(1):语法、引入方式、选择器、字体与背景
前端·css·html