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}!`;
相关推荐
weiabc4 分钟前
整数最接近等因数分解函数(汇编优化版)
开发语言·前端·javascript
小满zs4 分钟前
Next.js身份验证(better-auth)
前端·seo·next.js
IMPYLH10 分钟前
Linux 的 truncate 命令
linux·运维·服务器·前端·bash
invicinble17 分钟前
前端框架使用vue-cli( 第一层:依赖与环境层)
前端·vue.js·前端框架
七七powerful25 分钟前
mac电脑安装cmca根证书
java·前端·macos
invicinble27 分钟前
前端框架使用vue-cli (第五层:构建打包层--vue.config.js文件介绍以及环境文件)
javascript·vue.js·前端框架
神探小白牙27 分钟前
echarts环形图自定义
android·前端·echarts
故事和你9129 分钟前
洛谷-数据结构2-1-二叉堆与树状数组2
开发语言·javascript·数据结构·算法·ecmascript·动态规划·图论
ZC跨境爬虫31 分钟前
跟着 MDN 学 HTML day_28:(使用选择器 API 在 DOM 树中进行选择与遍历)
前端·ui·html·音视频·webrtc
东北甜妹32 分钟前
K8s Ingress
java·运维·前端