Skip to content

Commit

Permalink
Update declaring-instances.md
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari authored Nov 14, 2016
1 parent ecec184 commit 3ccdc8d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions regexp/declaring-instances.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Declaring instances

Doesn't matter if you use **constructor**
When declaring a `RegExp`, it oesn't matter if you use a **constructor**:

```js
const reUsername = /^[a-zA-Z0-9]+$/g
```

or **expression literal**
or if you use an **expression literal**:

```js
const reUsername = RegExp('^[a-zA-Z0-9]+$', 'g')
```

The important thing is store it into a variable to make it reusable.
The important thing is to store it into a variable to make it reusable.

As you can see I don't use `new` because it is unnecessary. According with [ECMAScript](http://www.ecma-international.org/ecma-262/6.0/#sec-regexp-constructor):
The use of `new` is unnecessary. According to [ECMAScript](http://www.ecma-international.org/ecma-262/6.0/#sec-regexp-constructor):

> The RegExp constructor is the %RegExp% intrinsic object and the initial value of the RegExp property of the global object. When RegExp is called as a function rather than as a constructor, it creates and initializes a new RegExp object. Thus the function call RegExp() is equivalent to the object creation expression new RegExp() with the same arguments.
> The RegExp constructor is the %RegExp% intrinsic object and the initial value of the RegExp property of the global object. When RegExp is called as a function rather than as a constructor, it creates and initializes a new RegExp object. Thus the function call RegExp(...) is equivalent to the object creation expression new RegExp(...) with the same arguments.
*Another reason for hate `new`, right?*
*Another reason for hating `new`, right?*

0 comments on commit 3ccdc8d

Please sign in to comment.