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}!`;
相关推荐
why技术1 小时前
我把这套 skills 引入团队,跑了好几个月后,说点真实体感。
前端·后端·ai编程
zhoulcc1 小时前
前端响应处理:AjaxResult与TableDataInfo的JSON结构区别及统一取值方案
前端·后端·bug·ajaxresult·tabledatainfo
泯泷1 小时前
第二章:你的第一个Lit组件 - 从零到"Hello, World"
前端·javascript·web components
lichenyang4532 小时前
网页与 JavaScript 注入基础
前端
lichenyang4532 小时前
理解注入脚本所需的 JavaScript 基础
前端
涛涛ing3 小时前
我们开源了公司的内部组件库,然后被各业务线骂成了筛子
前端
赵_叶紫3 小时前
1.Java AES-GCM 加解密入门:理解原理与字符串实战
前端
anyup3 小时前
uView Pro X 2.0 发布:弃用 UTS,全面支持 TypeScript 的 uni-app x 蒸汽模式 UI 框架
前端·uni-app·ai编程
多加点辣也没关系3 小时前
JavaScript|第42章:安全与最佳实践
开发语言·javascript·安全
泯泷3 小时前
第三章:lit-html的威力 - 精通声明式模板
前端·javascript·web components