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

Symbol.hasInstance

这篇翻译不完整。请帮忙从英语翻译这篇文章

Symbol.hasInstance用于判断某对象是否某构造器的实例。 因此你可以用它自定义instanceof 操作符在某个类上的行为。

Symbol.hasInstance 属性的属性特性:
writable false
enumerable false
configurable false

示例

你可以这样来自定义MyArray的instanceof行为:

class MyArray {  
  static [Symbol.hasInstance](instance) {
    return Array.isArray(instance);
  }
}
console.log([] instanceof MyArray); // true

技术标准

文档 状态 备注
ECMAScript 2015 (6th Edition, ECMA-262)
Symbol.hasInstance
Standard Initial definition.
ECMAScript 2017 Draft (ECMA-262)
Symbol.hasInstance
Draft  

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 50 (50) 未实现 ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 50.0 (50) 未实现 ? ?

参考

文档标签和贡献者

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