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

  • SEARCH
  • Home
  • 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 9072837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:16:05+00:00 2026-06-16T18:16:05+00:00

Possible Duplicate: How to convert a string value to a variable in javascript? In

  • 0

Possible Duplicate:
How to convert a string value to a variable in javascript?

In Javascript, I have an object that looks like this:

clock = function(){
    this.load = function(){
        alert("once");
    }

    this.once = function(){
        alert("load");
    }
}
var clock =  new clock();

On the page load, I call the load() function within the clock object like so

clock.load();

When the user clicks a link, however, I need to be able to run clock.once(). Calling it like this is fine, but does not fit the dynamic needs of what I’m doing.

Let’s say I need to call clock.once() when the user clicks an <a> tag:

$("a").click(function(){
    var id = $(this).attr("href").match(/[a-zA-Z]+/g);
    [id].once();
}

I figured that would work, where the object that the once() function is being called from is grabbed from the string id.

When running this, however, I get the following error:

Uncaught TypeError: Object clock has no method ‘once’

Manually calling once() by using clock.once() works fine.

  • 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-06-16T18:16:06+00:00Added an answer on June 16, 2026 at 6:16 pm

    [id].once is not not going to work because you aren’t referencing a particular array that you’ve created that contains clock objects. You would need a particular array where you had stored multiple instances of clock objects (if you had constructed the proper array).

    If you had previous create an array of clock objects:

    var clocks = [];
    clocks.push(new clock());
    clocks.push(new clock());
    

    Then, you could index into that particular array like this assuming id was a valid index into that array:

    clocks[id]
    

    If you’re really just asking how to convert a string to a number, you can do that several ways. Here are two common ways:

    parseInt(id, 10)
    +id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert this string to datetime I have to convert my string value
Possible Duplicate: How can I convert a string to boolean in JavaScript? I have
Possible Duplicate: convert string to 2D array using php I have the string like
Possible Duplicate: Convert.ToInt32() a string with Commas i have a value in the label
Possible Duplicate: How to convert string as object's field name in javascript I can
Possible Duplicate: C++ convert int and string to char* The function I use looks
Possible Duplicate: How to convert integer to string in C? I have a function
Possible Duplicate: Convert string to float in Objective-C I'd like to convert a string
Possible Duplicate: R: How to convert string to variable name? In R, I'm writing
Possible Duplicate: PHP ToString() equivalent How to convert a PHP object to a string?

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.