-2

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..

Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
  • 3
    [Regular expression literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) – Pointy Jul 10 '20 at 21:35
  • 1
    "because the slash is also used in regular expressions. Which I believe it's not the case in this code snippet" Why do you think it isn't? Because that's exactly what it is. – John Montgomery Jul 10 '20 at 21:48
  • @JohnMontgomery: I've never seen regex literals. Not in C#, Java, Object Pascal, Visual Basic, Python or other languages that I've worked with. Also the constructor word made me think in a different direction. Now I believe it is a regex literal... – Andrei Rînea Jul 10 '20 at 22:20

2 Answers2

1

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

Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Have a look at this maybe?

Simple patterns are constructed of characters for which you want to find a direct match. For example, the pattern /abc/ matches character combinations in strings only when the exact sequence "abc" occurs (all characters together and in that order). Such a match would succeed in the strings "Hi, do you know your abc's?" and "The latest airplane designs evolved from slabcraft." In both cases the match is with the substring "abc". There is no match in the string "Grab crab" because while it contains the substring "ab c", it does not contain the exact substring "abc".

Varun G
  • 44
  • 8