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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:38:49+00:00 2026-06-17T11:38:49+00:00

Suppose I have a Javascript object (the curly braces indicate it is so): {

  • 0

Suppose I have a Javascript object (the curly braces indicate it is so):

{
   a: function (something) {
      return something*2;
   },
   b: function () {
      var c = this.a(2);      //Does not work. Why?
      return c;
   }
}

What is the workaround to this?

  • 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-17T11:38:50+00:00Added an answer on June 17, 2026 at 11:38 am

    It not work because when you access the method b it context isn’t the instance from object that you made, it will try to search in the binded context or in window object.

    var x = {
       a: function (something) {
          return something*2;
       },
       b: function () {
          var c = x.a(2);      //Does not work. Why?
          return c;
       }
    }
    

    This way you are using the x as context to access the method a.

    Or you can use a new operator to create your object and the method as it prototype or direct method.

    When you do it, the result will be:

    var x = function() {
        return {
           a: function (something) {
              return something*2;
           },
           b: function () {
              var c = this.a(2);      //Does not work. Why?
              return c;
           }
        }
    }
    

    It will make you lose the prototype from x, when you make a new instance, but your code will work.

    Example:

    var y = new x();
    console.log(y.b());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a javascript object like this: window.config config.UI = { opacity: {
Suppose I have a Javascript file function js_main(args){ /* some code */ var x
For example suppose client side I have a JavaScript function function getLocation() { var
Suppose I have javascript within ASP.NET UserControl: function setValue(DataItem) { var selectedDate = DataItem.getMember('DomainNameKey').get_object();
Suppose I have a Javascript object which is initialized var letters = {q:0, t:0,
Suppose I have the following object in JavaScript: var object = { key1: value1,
Let's suppose I want to create a javascript class/object/function which have a method that
Suppose I have several javascript object {type:gotopage,target:undefined} {type:press,target:a} {type:rotate,target:long} How can I add this
Possible Duplicate: Pick random property from a Javascript object suppose I have a javascript
Suppose I create a custom object/javascript class (airquotes) as follows: // Constructor function CustomObject(stringParam)

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.