Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How to call a specific function from inside a subfunction in javascript?

How do I call function "a" from "a.v" without a direct reference "a()"

function a(){
    alert("1");
    this.v=function(){alert("hi")};
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

One way I can think of doing this without repeating a:

function a(){
    let indirect = arguments.callee;
    alert("1");
    indirect.v=function(){ indirect(); };
}

a();
a.v();

But this does not work under strict mode and you must call a before calling a.v.

You could also do:

function a(){
   alert('1');
   this.v = () => this();
}

a.v = a;
a.v();

This way you don't call a() and it also works under strict mode.

about 4 years ago · Juan Pablo Isaza Report

0

Set its v property outside the function:

function a() {
  alert("1");

}

a.v = function() {
  a()
  alert("hi")
};

a.v()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!