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 8629157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:43:49+00:00 2026-06-12T08:43:49+00:00

If I create a Class with two method like following: var Car = function()

  • 0

If I create a Class with two method like following:

var Car = function() {}
Car.prototype = {
    run: function() {
        alert('run');
    },
    stop: function() {
        alert('stop');
    }
}

And when the DOM is ready will call test() method,
and this test() method will create a instance of Car and call the method of Car

$(document).ready(function() {
    test("run");
});
function test(method) {
    var instance = new Car();
    // call instance.run()
}

I know I have to use apply() method,
but I have tried lots of times and failed
So, how can I use apply() method in Object?

  • 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-12T08:43:50+00:00Added an answer on June 12, 2026 at 8:43 am

    An object in javascript is an associative array, so you can use the [] operator to address by string any member of the object, functions as well.

    function test(method) {
        var instance = new Car();
        instance[method]();
    }
    

    this will allow to call a function by name over the object Car.

    See it working on JsFiddle.

    The context inside the called method will properly point to the newly created Car instance without any additional effort, that I guess is what you want. Using apply or call is generally used when you need to change the default ‘this‘ value to something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at the following two ways to create a new object of class Y:
I have two classes like the following: class Super(object): def __init__(self, arg): self.arg =
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)
I need to create a class which calculates the distance between two points. I
Here is the code, I defined two class named Father and Son, and create
Can we able to create two instance of log4j in class one to write
I'm trying to use the DSACryptoServiceProvider class with C# to create two DLLs: one
So I'm doing this project for my OO class. We need to create two
I want to create a specific generic method in Scala. It takes two parameters.
I have a template class, and would like to write a member method that's

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.