当前位置:网站首页>The Object of the method
The Object of the method
2022-08-05 11:55:00 【Han.】
When learning, the teacher encounters and uses itObject中的方法,So list it,See what it can do,It is also convenient for future development and direct use
1 Object.assign
Copies all enumerable returned and own properties from one or more source objects to target objects
const target={
a:1,b:2}
const source={
b:4,c:5}
const target=Object.assign(target,source)
第一个参数为目标对象,后面的参数Can be an object that requires one or more replications,The final structure returnsThe target object after copying
注意1:使用Object.assignMaking a deep copy only copies the first level of references,Therefore, deep copying of multi-level reference objects is not possible
注意2:复制null和undefined时会忽略,Only enumerable types and their own properties can be copied,一般只有stringHas its own enumerable properties
2 Object.create
用于创建一个新对象,Use an existing object as a prototype for a new object
使用Object.create实现继承
function Person(name,age){
this.name=name
this.age=age
}
Person.prototype.getName=function(){
return this.name
}
function Student(name,age,grade){
Person.call(this,name,age)
this.grade=grade
}
Student.prototype=Object.create(Person.prototype)
Strdent.prototype.constructor=Student
3 Object.defineProperty
直接在一个对象上定义新的属性或修改现有属性,并返回该对象
Object.defindPropertiy(obj,{
set(val){
obj==val
}
get(){
return obj
}
})
4 Object.entries
返回一个键值对数组
5 Object.getOwnPropertyNames
Returns the property names of all properties of an object(包括不可枚举、属性,但不包括symbol值作为名称的属性)
6 Object.getOwnPropertySymbols
Returns an object to useSymbol值作为属性名
7 Object.hasOwn
Determines whether the property is a direct property of the object,This method does not check properties on the object's prototype chain
8 Object.keys
Returns an array of object enumerable property names
9 Object.values
返回对象的属性值数组
边栏推荐
猜你喜欢

IPMP、PMP、CPMP三个证书该如何选择,有什么区别,哪个对于工作上的

Go Quick Start Guide: Basic Types

No developers, received a job to develop an IoT system, do you want to do it?

自从用了 Kiali 以后才知道,配置 Istio 的 流量管理 是如此容易

2022杭电多校联赛第六场 题解

Learning Deep Compact Image Representations for Visual Tracking

C language classic examples - find the largest number in a series of numbers

STM32H743IIT6学习笔记02——USART

Machine Learning - Logistic Regression

多业务模式下的交易链路探索与实践
随机推荐
数据治理体系演进简介
STM32H743IIT6学习笔记02——USART
Go compilation principle series 9 (function inlining)
Qt::qcustomplot 和 qchart数据填充相关
Byte Qiu Zhao confused me on both sides, and asked me under what circumstances would the SYN message be discarded?
花的含义
尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
Digital-intelligent supply chain system in the household appliance industry: efficiently integrate the supply chain and enhance the core competitiveness of household appliance enterprises
力扣330 按要求补齐数组(贪心)
KVM virtualization technology-NUMA technology and application
什么是缓冲区(buffer),什么是缓存(cache)
LeetCode刷题(8)
学习用于视觉跟踪的深度紧凑图像表示
灰度值与热成像理解
知乎提问:中国是否还能实现伟大民族复兴
小红的aba子序列(离散化、二分、dp维护区间最短)
2022.08.02_每日一题
Go编译原理系列9(函数内联)
【硬件架构的艺术】学习笔记(3)处理多个时钟
碘乙酰胺在Desthiobiotin-Iodoacetamide试剂中的作用?