首页 > 解决方案 > What is the meaning of forward slash in a JavaScript expression?

问题描述

Stumbling upon a piece of JavaScript in a library I found this:

let useBlobFallback = /constructor/i.test(window.HTMLElement) || !!window.safari || !!window.WebKitPoint

but I can't find the meaning of the /constructor/i. Even searching online produces meaningless results because of the 'constructor' word and/or because the slash is also used in regular expressions. Which I believe it's not the case in this code snippet..

标签: javascriptsyntax

解决方案


This is a RegExp literal. It's equivalent to new RegExp('constructor', 'i').test(window.HTMLElement).


推荐阅读