/constructor)
    2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 
  13. Methods 
    1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated 
    2. [ ` Object.prototype.__defineSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__) Deprecated 
    3. [ ` Object.prototype.__lookupGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__) Deprecated 
    4. [ ` Object.prototype.__lookupSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__) Deprecated 
    5. [ ` Object.prototype.hasOwnProperty() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
    6. [ ` Object.prototype.isPrototypeOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
    7. [ ` Object.prototype.propertyIsEnumerable() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
    8. [ ` Object.prototype.toLocaleString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
    9. [ ` Object.prototype.toString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
    10. [ ` Object.prototype.valueOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

##  In this article

  * Syntax 
  * Examples 
  * Specifications 
  * Browser compatibility 
  * See also 

#  RegExp.prototype.compile()

**Deprecated:** This feature is no longer recommended. Though some browsers
might still support it, it may have already been removed from the relevant web
standards, may be in the process of being dropped, or may only be kept for
compatibility purposes. Avoid using it, and update existing code if possible;
see the  compatibility table  at the bottom of this page to guide your
decision. Be aware that this feature may cease to work at any time.

**Note:** The ` compile() ` method is only specified for compatibility
reasons. Using ` compile() ` causes the otherwise immutable regex source and
flags to become mutable, which may break user expectations. You can use the [
` RegExp() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) constructor to
construct a new regular expression object instead.

The **` compile() ` ** method of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances is used to
recompile a regular expression with new source and flags after the ` RegExp `
object has already been created.

##  Syntax

js

    
    
    compile(pattern, flags)
    

###  Parameters

` pattern `

    

The text of the regular expression.

` flags `

    

Any combination of [ flag values ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#flags) .

###  Return value

None ( [ ` undefined ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/undefined) ).

##  Examples

###  Using compile()

The following example shows how to recompile a regular expression with a new
pattern and a new flag.

js

    
    
    const regexObj = new RegExp("foo", "gi");
    regexObj.compile("new foo", "g");
    

##  Specifications

Specification  
---  
[ ECMAScript Language Specification  
#  sec-regexp.prototype.compile
](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-
browsers.html#sec-regexp.prototype.compile)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ ` RegExp ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Sep 12, 2023  by  [ MDN contributors ](/