Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Object.getOwnPropertySymbols()

该新特性属于 ECMAScript 2015(ES6)规范,在使用时请注意浏览器兼容性。

概述

Object.getOwnPropertySymbols() 方法会返回一个数组,该数组包含了指定对象自身的(非继承的)所有 symbol 属性键。

语法

Object.getOwnPropertySymbols(obj)

参数

obj
任意一个对象

描述

该方法和 Object.getOwnPropertyNames() 类似,但后者返回的结果只会包含字符串类型的属性键,也就是传统的属性名

示例

var obj = {};
var a = Symbol("a");
var b = Symbol.for("b");

obj[a] = "localSymbol";
obj[b] = "globalSymbol";

var objectSymbols = Object.getOwnPropertySymbols(obj);

console.log(objectSymbols.length); // 2
console.log(objectSymbols)         // [Symbol(a), Symbol(b)]
console.log(objectSymbols[0])      // Symbol(a)

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
Object.getOwnPropertySymbols
Standard Initial definition.

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 33.0 (33.0) 未实现 未实现 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 33.0 (33.0) 未实现 未实现 未实现

相关链接

文档标签和贡献者

 此页面的贡献者: ziyunfei
 最后编辑者: ziyunfei,