Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:55:57+00:00 2026-05-24T08:55:57+00:00

The following code: var r = /^[0-9A-Z]$/.test; r(A) Throws ‘TypeError: can’t convert undefined to

  • 0

The following code:

var r = /^[0-9A-Z]$/.test;
r("A")

Throws ‘TypeError: can’t convert undefined to object’

How else could I assign the test function to a variable, for passing in functions, later evaluation, etc.? (Without wrapping the regex in another function)

Update:

Consider this bit of valid code before answering:

var o = { f: function() { return 1 } };
var a = o.f;
var b = a();     // b = 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:55:58+00:00Added an answer on May 24, 2026 at 8:55 am

    It has to do with the value of this inside the test method.

    For example:

    var obj = {
      method: function () { return this === obj }
    };
    
    obj.method(); // true
    
    var method = obj.method;
    method(); // false
    

    If you call the test method “as a function” -as your example r();-, the this value will refer to undefined (for built-in or strict functions in ECMAScript 5, in the above example this will refer to the global object).

    Calling any method of RegExp.prototype with a this value that is not a RegExp object, will always generate this TypeError exception, quoting the spec:

    15.10.6 Properties of the RegExp Prototype Object

    In the following descriptions of functions that are properties of the RegExp prototype object, the phrase “this RegExp object” refers to the object that is the this value for the invocation of the function; a TypeError exception is thrown if the this value is not an object or an object for which the value of the [[Class]] internal property is not “RegExp”.

    However you could bind the test method to your r function, using the Function.prototype.bind method:

    var re = /^[0-9A-Z]$/,
        r = re.test.bind(re);
    
    r("A"); // true
    

    Or using call or apply:

    var r = re.test;
    r.call(re, "A"); // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code.. $(document).ready(function(){ $(#test a).click(function(){ var labelTo = $(this).text(); window.location =
In JavaScript let's say we have the following code var test = 'd'; if
I have the following code var replyName = "1"; var test = "<div id=replyName></div>"
The following code: var constant = Expression.Constant(find me, typeof(string)); // memberExpression evaluates to a
in the following code : var benq:Base64Encoder = new Base64Encoder(); benq.encode(force,0,5); var tmp:String =
Given the following code: var people = new List<person>(){ new person { Name =
I have the following code: var tempIdx = document.getElementById('cityBuild').selectedIndex; var tempBuilding = document.getElementById('cityBuild').options[tempIdx].value; //
I have the following code: var sl: THashedStringList; begin sl:= THashedStringList.Create; sl.Duplicates := dupIgnore;
Namely, how does the following code: var sup = new Array(5); sup[0] = 'z3ero';
I am using ASP.NET 3.5 with iTextSharp and I have the following code: var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.