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}!`;
相关推荐
爱吃大芒果5 分钟前
Flutter for OpenHarmony 实战:mango_shop 路由系统的配置与页面跳转逻辑
开发语言·javascript·flutter
qq_177767379 分钟前
React Native鸿蒙跨平台实现消息列表用于存储所有消息数据,筛选状态用于控制消息筛选结果
javascript·react native·react.js·ecmascript·harmonyos
weixin_3954489110 分钟前
main.c_cursor_0129
前端·网络·算法
沐雪架构师22 分钟前
LangChain 1.0 Agent开发实战指南
开发语言·javascript·langchain
2501_9400078934 分钟前
Flutter for OpenHarmony三国杀攻略App实战 - 战绩记录功能实现
开发语言·javascript·flutter
摘星编程38 分钟前
React Native + OpenHarmony:自定义useEllipsis省略号处理
javascript·react native·react.js
2401_859049081 小时前
git submodule update --init --recursive无法拉取解决
前端·chrome·git
这是个栗子1 小时前
【Vue代码分析】前端动态路由传参与可选参数标记:实现“添加/查看”模式的灵活路由配置
前端·javascript·vue.js
刘一说1 小时前
Vue 动态路由参数丢失问题详解:为什么 `:id` 拿不到值?
前端·javascript·vue.js
熊猫钓鱼>_>2 小时前
动态网站发布部署核心问题详解
前端·nginx·容器化·网页开发·云服务器·静态部署