Reflect.get
Reflect.get()
方法的工作方式,就像从对象 (target[propertyKey]
) 中获取属性,但它是作为一个函数执行的。
语法
Reflect.get(target, propertyKey[, receiver])
参数
target
需要取值的目标对象propertyKey
需要获取的值的键值receiver如果遇到 getter,此值将提供给目标调用。
返回值
属性值。
异常
描述
Reflect.get 方法允许你从一个对象中取值
。就如同函数(function)里的 属性访问器 语法。
示例
使用Reflect.get()
// Object
var obj = { x: 1, y: 2 };
Reflect.get(obj, 'x'); // 1
// Array
Reflect.get(['zero', 'one'], 1); // "one"
// Proxy with a get handler
var x = {p: 1};
var obj = new Proxy(x, {
get(t, k, r) { return k + 'bar'; }
});
Reflect.get(obj, 'foo'); // "foobar"
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Reflect.get' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Reflect.get' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 49 | (Yes) | 42 (42) | No support | No support | 10 |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | 49 | (Yes) | 42.0 (42) | No support | No support | 10 |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com