标签:EDA col let 通过 array object 对象属性 布尔 sed
entries
keys
values
is
assign
create
toSting
Proety
defineProperty(obj,key,propety)
Object.entries(),Object.keys(),Object.values()
理解:获取对象的key、value,组成的数组
使用:
参数:
返回值:转换之后的数组
let obj1 = {‘a‘:1,"b":2,"c":3}; let res1 = Object.entries(obj1); let res2 = Object.keys(obj1); let res3 = Object.values(obj1); console.log(‘返回值‘,res1); //["a", 1], ["b", 2], ["c", 3]] console.log(‘返回值‘,res2); //["a", "b", "c"] console.log(‘返回值‘,res3); //[1, 2, 3]
Object.is()
理解:判断传入的两个参数是否相等
返回值:返回布尔值
注意值:可以区分NAN
let obj1 = {‘a‘:1,"b":2,"c":3}; let res1 = Object.is("a","b"); let res2 = Object.is(NaN, NaN) console.log(‘返回值‘,res1); //false console.log(‘返回值‘,res2); //true
Object.assign()
理解:合并对象,将第二个及后面的参数合并到第一个参数上
返回值:合并之后的第一个参数
原对象:改变
let obj1 = {‘a‘:1,"b":2,"c":3}; let res1 = Object.assign(obj1,{‘o‘:99}); let obj2 = {‘a‘:1,"b":2,"c":3}; let res2 = Object.assign({},obj1,{‘o‘:99}); console.log(‘原数组‘,obj1); //{a: 1, b: 2, c: 3, o: 99} console.log(‘返回值‘,res1); //{a: 1, b: 2, c: 3, o: 99} console.log(‘原数组‘,obj2); //{a: 1, b: 2, c: 3} console.log(‘返回值‘,res2); //{a: 1, b: 2, c: 3, o: 99}
Object.create()
理解:创建对象,并将对象的__proto__属性上添加对象,对象是传入的参数
返回值:新创建的对象
let obj = { x : 1, y : 2, z :3, name : ‘abc‘, study : function () { console.log(this.name) } } let newObj = Object.create(obj); console.dir(newObj);
Object.Proety()
理解:对象代理,通过对象代理可以获取指定的对象属性和方法
let newObj = (function(){ let obj = { x : 10, y : 100, z : 1000 } return new Proxy(obj,{ get(obj,property){ if (property != ‘x‘){ return obj[property] } } }) })(); console.log(newObj.x) //undefined console.log(newObj.y) //100
Object.prototype.toString
理解:转换成字符串
let a = Object.prototype.toString; console.log(a.call("aaa")); //[object String] console.log(a.call(1)); //[object Number] console.log(a.call(true)); //[object Boolean] console.log(a.call(null)); //[object Null] console.log(a.call(undefined)); //[object Undefined] console.log(a.call([])); //[object Array] console.log(a.call(function() {})); //[object Function] console.log(a.call({})); //[object Object]
属性的遍历
标签:EDA col let 通过 array object 对象属性 布尔 sed
原文地址:https://www.cnblogs.com/shaokevin/p/9789831.html