当前位置:网站首页>ES6 从入门到精通 # 08:扩展的对象的功能
ES6 从入门到精通 # 08:扩展的对象的功能
2022-07-28 03:13:00 【凯小默】
说明
ES6 从入门到精通系列(全23讲)学习笔记。
扩展的对象的功能
es6 直接写入变量和函数,作为对象的属性和方法。
const name = "kaimo",
age = 313;
// es5
const person = {
name: name,
age: age,
getName: function () {
console.log(this.name)
}
}
// es6 简写
const person = {
name,
age,
getName() {
console.log(this.name)
}
}
person.getName()

function fn(x, y) {
return {
x, y};
}
console.log(fn(1,2));

const obj = {
};
obj.isShow = true;
const name = "kaimo";
obj[name + "bc"] = 123;
obj['f'+name] = function() {
console.log(this)
}
console.log(obj)
// 可以改成
const name = "kaimo";
const obj = {
isShow: true,
[name + "bc"]: 123,
['f'+name]() {
console.log(this)
}
};
console.log(obj)

对象的方法
// is() 比较两个值严格相等
console.log(NaN === NaN);
console.log(Object.is(NaN, NaN));

// assign() 对象的合并(浅拷贝)返回合并之后的新对象
let newObj = Object.assign({
}, {
name: "kaimo"}, {
age: 313});
console.log(newObj);

边栏推荐
- Redis persistence mechanism
- 鼠标操作和响应
- Win11 how to rename an audio device
- Defect detection of BP SVM system design of leaf defect detection
- PCB丝印如何摆?请查收这份手册!
- How does win11 display fixed applications?
- vi命令详解
- "Introduction to engineering electromagnetic field" after class exercises with answers
- [5g NR] RRC reject analysis
- 工程电磁场复习基本知识点
猜你喜欢

redis源码分析(谁说C语言就不能分析了?)

53. Maximum Subarray最大子数组和

Redis经典面试题总结

整合SSM实现增删改查搜索

Analysis of redis network model

How to arrange PCB screen printing? Please check this manual!

Raspberry pie development relay control lamp

20220727 use the Bluetooth module hc-05 of Huicheng technology to pair mobile phones for Bluetooth serial port demonstration

在线问题反馈模块实战(十六):实现查详情功能

如何让外网访问内网IP(esp8266网页使用)
随机推荐
max_ pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
静态博客搭建工具汇总
golang 获取循环嵌套结构的tag
Acid characteristics of MySQL transactions and example analysis of concurrency problems
关于湖北文理学院平衡信标组的疑问回应
Unity背包系统
力扣(LeetCode)208. 实现 Trie (前缀树)(2022.07.27)
【Codeforces Round #806 (Div. 4)(A~F)】
golang gorm查询任意字段的组装方法
Summary of concurrent programming interview questions
叶子识别 颜色的特征提取 缺陷检测等
C language to achieve a dynamic version of the address book
C WinForm development: how to add pictures to project resources
Redis 5 kinds of data structure analysis
【uni-app高级实战】手把手带你学习一个纯实战复杂项目的开发2/100
数据湖(十七):Flink与Iceberg整合DataStream API操作
《工程电磁场导论》课后习题附答案
[acwing 327. corn field] shaped pressure DP
[download file] uniapp develops small programs, downloads files and saves them locally
Four methods of closing forms in C #