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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:59:07+00:00 2026-06-15T13:59:07+00:00

var abc = { ‘a’: 10, ‘b’: 10, c: function() { //like if I

  • 0
var abc = {
    'a': 10,
    'b': 10,
    c: function() {
        //like if I have many many functions in c
        init_a();
        multiple();

        function init_a() {
            abc.a = 30;
        }

        function multiple() {
            alert(abc.a * abc.b);
        }

        function minus() {
            alert(abc.a - abc.b);
        }
        return {
            function myalert() {
                var result = abc.a + abc.b;
                alert(result);
            }
        }
    },
    d: function() {
        abc.c.myalert(); // ???  error??
        abc.c().myalert(); // ??? error??  **it run all functions in c but not just myalert, strange things happening...
    }

}
abc.d();

whats the correct syntax to call the ‘myalert()’ function in function d?

  • 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-15T13:59:08+00:00Added an answer on June 15, 2026 at 1:59 pm

    The myalert() function iswas local to abc.c(), so that’s not possible.

    You could let c() return myalert() though:

    c: function() {
        return function myalert() {
          // whatever
        }
    }, d: function() {
        this.c()()
    }
    

    Note that the returned function doesn’t have to be named, i.e. return function() { .. }.

    Update

    If you want to call it like this.c().myalert(), then c() needs to return an object instead of the function directly:

    c: function() {
        return {
            myalert: function() { ... }
        }
    }
    

    Update 2

    Your c() function now contains other statements besides the declaration of myalert(). When called, init_a() and multiple() get called before it returns.

    I would suggest refactoring your code, such as, move myalert() into the main object instead:

    var abc = {
        a: 10,
        b: 10,
        c: function() { ... }
        myalert: function() { ... }
        d: function() {
            this.myalert();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making ajax call like this $(document).ready(function() { var abc = new Array();
given i have the following block of code (function(){ var mb = { abc:function(){
If I have a method chain like the following: var abc = new ABC();
I have strings like this: var abc = 00345667; var def = 002776766; The
I have strings like this: var abc = 002; var def = 023; How
var abc = '5'; $('#test').click(meraFunc(abc)); function meraFunc(abc) { alert(abc); } <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <input type=button
How are function declarations handled? var abc = ''; if (1 === 0) {
function fake() { var ffake; } fake.prototype.abc = function() { fake.ffake = 1;//not working
Please see my exaple: var AbcVar = abc; function Abc(AbcVar){ console.log(AbcVar); } It this
I have this code: var str = ' abc'; str.replace( ,); but it is

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.