Object static methods

简介: Object static methods

Object.values()

var obj = Object.create({
    a: "qux",
    d: "qux"
});
obj.a = "foo";
obj.b = "bar";
obj.c = "baz";
var v = Object.values(obj);
console.log(v); //["foo", "bar", "baz"]


Object.entries()

var obj = Object.create({
    a: "qux",
    d: "qux"
});
obj.a = "foo";
obj.b = "bar";
obj.c = "baz";
var e = Object.entries(obj);
console.log(e);
// (3) [Array(2), Array(2), Array(2)]
// 0: (2) ["a", "foo"]
// 1: (2) ["b", "bar"]
// 2: (2) ["c", "baz"]
// length: 3


Object.getOwnPropertyDescriptors()

var object = {
    a: 1
};
var B = typeof Symbol === 'function' ? Symbol('b') : 'b';
object[B] = 2;
var O = Object.defineProperty(object, 'c', {
    value: 3
});
var D = Object.getOwnPropertyDescriptors(O);
console.log(object); // VM63:11 {a: 1, c: 3, Symbol(b): 2}
console.log(B); // Symbol(b)
console.log(O); // {a: 1, c: 3, Symbol(b): 2}
console.log(D);
// {a: {…}, c: {…}, Symbol(b): {…}}
// a: {value: 1, writable: true, enumerable: true, configurable: true}
// c: {value: 3, writable: false, enumerable: false, configurable: false}
// Symbol(b): {value: 2, writable: true, enumerable: true, configurable: true}点击复制复制失败已复制


注意

该方法不支持未定的描述符,如下所示:

var P = new Proxy({
    a: 1
}, {
    getOwnPropertyDescriptor: function(t, k) {}
});
console.log(Object.getOwnPropertyDescriptors(P).hasOwnProperty('a')
目录
相关文章
|
4天前
object
==是进行对象的地址值比较,如果确实需要字符串的内容比较,可以使用两个方法 public boolean equals(0bjectobj):参数可以是任何对象,只有参数是一个字符串并且内 容相同的才会给true;否则返回false 注意事项: 1.任何对象都能用object进行接收。 2.equals方法具有对称性,也就是a.equals(b)和b.equals(a)效果一样。 3.如果比较双方一个常量一个变量,推荐把常量字符串写在前面。 推荐:"abc".equals(str) 不推荐:str.equals("abc") public boolean egualsIgnoreCas
13 2
|
4天前
FeignClient【问题】Cannot deserialize value of type``from Object value (token `JsonToken.START_OBJECT`)
FeignClient【问题】Cannot deserialize value of type``from Object value (token `JsonToken.START_OBJECT`)
245 0
|
5月前
Object.fromEntries
Object.fromEntries
24 0
|
9月前
|
文字识别 API
The value is not an object
The value is not an object
104 1
|
11月前
|
Java
Object
Object
53 0
|
Java Android开发
The method call() of type XXX must override a superclass
The method call() of type XXX must override a superclass
77 0
单方法对象(Single-method Object)
单方法对象(Single-method Object)
77 2
Object.fromEntries()
Object.fromEntries()
109 0
|
编译器
public <T> T method(T t)方法详解
public <T> T method(T t)方法详解
248 0
public <T> T method(T t)方法详解
|
JavaScript 前端开发 Web App开发
Function和Object 应该知道的
javascript有5种基础的内建对象(Fundamental Objects),Object、Function、Error、Symbol、Boolean,而Object/Function尤为特殊,是定义其他内建对象或者普通对象和方法的基础。
1439 0