当前位置:网站首页>ES6 from getting started to mastering 08: extended object functions
ES6 from getting started to mastering 08: extended object functions
2022-07-28 03:37:00 【Kai Xiaomo】
explain
ES6 From entry to Mastery Series ( whole 23 speak ) Learning notes .
Extended object functionality
es6 Write variables and functions directly , Properties and methods as objects .
const name = "kaimo",
age = 313;
// es5
const person = {
name: name,
age: age,
getName: function () {
console.log(this.name)
}
}
// es6 Abbreviation
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)
// You can change to
const name = "kaimo";
const obj = {
isShow: true,
[name + "bc"]: 123,
['f'+name]() {
console.log(this)
}
};
console.log(obj)

Object method
// is() Compare two values that are strictly equal
console.log(NaN === NaN);
console.log(Object.is(NaN, NaN));

// assign() Merge of objects ( Shallow copy ) Return the new object after merging
let newObj = Object.assign({
}, {
name: "kaimo"}, {
age: 313});
console.log(newObj);

边栏推荐
- Shell: one click deployment PXE
- Leetcode 208. implement trie (prefix tree) (2022.07.27)
- golang gorm查询任意字段的组装方法
- Collection | 0 basic open source data visualization platform flyfish large screen development guide
- ThreadLocal usage scenario
- 一篇文章掌握Postgresql中对于日期类数据的计算和处理
- leetcode刷题:动态规划08(分割等和子集)
- deepstream 检测结果截图
- 95后阿里P7晒出工资单:真的是狠狠扎心了...
- tensorboard使用记录
猜你喜欢

鼠标操作和响应

Redis persistence mechanism

Outlook 教程,如何在 Outlook 中使用颜色类别和提醒?

Redis implements distributed locks

VMware virtual machine network settings
D2DEngine食用教程(4)———绘制文本

Redis source code analysis (who says C language can't analyze it?)

How to make the Internet access the intranet IP (used by esp8266 web pages)

Light year admin background management system template

沃尔沃:深入人心的“安全感” 究竟靠的是什么?
随机推荐
我的创作纪念日
Light year admin background management system template
Shell: resource monitoring script and high load alarm
D2dengine edible tutorial (4) -- draw text
Redis source code analysis (who says C language can't analyze it?)
单调栈——739. 每日温度
AI首席架构师12-AICA-百度OCR垂类规模化落地实践
同时导出多个excel,并且一个excel中包含多个sheet
容器相关的概念
verticle-align行内元素垂直居中对齐
Integrate SSM to realize search of addition, deletion, modification and query
SQL Server备份数据库的方法
An article grasps the calculation and processing of date data in PostgreSQL
Unity背包系统
leetcode刷题:动态规划08(分割等和子集)
Daily practice ----- realize the lottery function of two-color ball. Rules: Six non repeating numbers are randomly selected from 36 red balls, and one from 15 basketball is randomly selected to form a
pip-script.py‘ is not present Verifying transaction: failed
Responsive high-end website template source code Gallery material resource download platform source code
Use of custom annotations
什么是Tor?Tor浏览器更新有什么用?