当前位置: 首页 > news >正文

Day02-ES6

一.proxy代理

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>let obj = {name: "xiaohao",age: 18}let handler = {get: function (target, key) {console.log(key);// console.log("无权访问" + key);return target[key];},set: function (target, key, value) {console.log("设置" + key + "成功");target[key] = value;}}// 实例化代理var proxy = new Proxy(obj, handler);console.log(obj);console.log(proxy);console.log(proxy.name);        // proxy.getproxy.gender = "男";            // proxy.setconsole.log(proxy);</script></body></html>

二.reflect反射

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>let obj = {name: "xiaohao",age: 18,get fun() {return this.name;}}// Reflect 反射// get console.log(Reflect.get(obj, "name"));var newObj = {name: "xiaogu",age: 20}console.log(Reflect.get(obj, "fun", newObj));Reflect.set(obj, "gender", "男");console.log(obj);</script></body></html>

三.组合使用

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>let obj = {name: "xiaohao",age: 18}let handler = {get: function (target, key) {// ...操作return Reflect.get(target, key);},set: function (target, key, value) {return Reflect.set(target, key, value);}}// 实例化代理对象let proxy = new Proxy(obj, handler);console.log(proxy.name);proxy.gender = "男";console.log(proxy);</script></body></html>

四.ES6字符串

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><div></div><script>let str = "hello";// 重复console.log(str.repeat(3));// 补全console.log(str.padStart(10, "o"));// 模板字符串document.querySelector("div").innerHTML = `<h1>hello</h1>`;</script></body></html>

五.ES6数值

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>// 十进制let num = 10;// 二进制let num1 = 0b1001;console.log(num1);// 八进制let num2 = 0o1001;console.log(num2);// 十六进制let num3 = 0x1001;console.log(num3);// 幂运算console.log(num ** 3);// parseInt()方法补充console.log(parseInt("10"));console.log(parseInt("10", 8));let arr = ["1", "2", "3"];console.log(arr.map(parseInt));parseInt("1", 0);       // 1parseInt("2", 1);       // NaNparseInt("3", 2);       // NaN</script></body></html>

六.ES6对象

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>let name = "zhangsan";let age = 18;function sayHi() {console.log("hello");}// 对象的简写形式var obj = {name,age,sayHi}let obj2 = {gender: "男"}console.log(obj);obj.sayHi();// 扩展运算符// 扩展运算符(...)用于取出参数对象所有可遍历属性然后拷贝到当前对象。let newObj = { ...obj, ...obj2 };        // 浅拷贝console.log(newObj);</script></body></html>

七.ES6数组

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>// Array.of() 创建数组console.log(Array.of(1, 2, 3, 4, 5, 6, 7));var map = new Map();map.set("name", "xiaohao");map.set("age", "18");console.log(Array.from(map));// arr.flat()  抚平数组let arr = [1, 2, 3, [4, [5, 6, [7, 8, 9]]]];console.log(arr);console.log(arr.flat(1));console.log(arr.flat(2));console.log(arr.flat(3));// 扩展运算符let arr2 = [1, 2, 3, 4, 5];let arr3 = [...arr2];console.log(arr3);</script></body></html>

http://www.lryc.cn/news/270755.html

相关文章:

  • 2023年12月记录内容管理
  • 【测试基础】构造测试数据之 MySQL 篇
  • 基于单片机的语音识别自动避障小车(论文+源码)
  • 2023年“中银杯”四川省职业院校技能大赛“云计算应用”赛项样题卷①
  • 【信息安全原理】——入侵检测与网络欺骗(学习笔记)
  • JVM GC 算法原理概述
  • 【数值分析】LU分解解Ax=b,matlab自己编程实现
  • 华为HCIE-Datacom课程介绍
  • QT(C++)-QTableWight添加行和删除空行
  • 软件测试/测试开发丨Python 面向对象编程思想
  • 一次降低进程IO延迟的性能优化实践——基于block层bfq调度器
  • C语言易错知识点十(指针(the final))
  • React 18 新增的钩子函数
  • 安装与部署Hadoop
  • MySQL 8.0 InnoDB Tablespaces之General Tablespaces(通用表空间/一般表空间)
  • 循环生成对抗网络(CycleGAN)
  • 数组--53.最大子数组和/medium
  • centos 编译安装 python 和 openssl
  • 【nodejs】前后端身份认证
  • 数据结构【线性表篇】(三)
  • Python装饰器的专业解释
  • vue3框架笔记
  • pytest --collectonly 收集测试案例
  • dev express 15.2图表绘制性能问题(dotnet绘图表)
  • WorkPlus:领先的IM即时通讯软件,打造高效沟通协作新时代
  • 学习SpringCloud微服务
  • WPF 显示气泡提示框
  • L1-062:幸运彩票
  • python+vue高校体育器材管理信息系统5us4g
  • 10 款顶级的免费U盘数据恢复软件(2024 年 更新)