From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/symbol/search/index.html | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/symbol/search/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/symbol/search') diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/search/index.html b/files/zh-cn/web/javascript/reference/global_objects/symbol/search/index.html new file mode 100644 index 0000000000..c1efdd302e --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/search/index.html @@ -0,0 +1,113 @@ +--- +title: Symbol.search +slug: Web/JavaScript/Reference/Global_Objects/Symbol/search +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/search +--- +
{{JSRef}}
+ +
+ +

Symbol.search 指定了一个搜索方法,这个方法接受用户输入的正则表达式,返回该正则表达式在字符串中匹配到的下标,这个方法由以下的方法来调用 {{jsxref("String.prototype.search()")}}。

+ +

更多信息请参见 {{jsxref("RegExp.@@search", "RegExp.prototype[@@search]()")}} 和{{jsxref("String.prototype.search()")}}.

+ +
{{js_property_attributes(0,0,0)}}
+ +

案例

+ +

自定义字符串搜索

+ +
class caseInsensitiveSearch {
+  constructor(value) {
+    this.value = value.toLowerCase();
+  }
+  [Symbol.search](string) {
+    return string.toLowerCase().indexOf(this.value);
+  }
+}
+
+console.log('foobar'.search(new caseInsensitiveSearch('BaR')));
+// expected output: 3
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ES2015')}}规范中定义的几个部分
{{SpecName('ESDraft', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
基本支持{{CompatChrome(50)}}{{ CompatGeckoDesktop(49) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基本支持{{CompatNo}}{{CompatNo}}{{ CompatGeckoMobile(49) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

参见

+ + -- cgit v1.2.3-54-g00ecf