Solved

Java Script nested call

Posted on 2016-08-08
3
90 Views
Last Modified: 2016-08-08
Hi,

I am learning javascript, trying out the below code, it is not working.
Just wanted to check if the below is feasible.

<html>
<script type = 'text/javascript'>
function call1()
{
this.c = 10;
document.write("call done");
}
function call2()
{
cta = new call1();
//document.write("call2"+cta.c);
}
function execute(){
var abc = new call2();
document.write(abc.cta.c); // can I do like this. if this is wrong any other way.

}
</script>
<body>
<input type = button onclick = "execute()"/>
</body>
</html>
--------------------------------------------
I have created a function "call1". This has a variable "C".
, and created an object for it in another function "call2"
then created a function "execute" to create an object for "call2"
now wanted to access the variable "C" in "call1" through "call2"

Is it possible to do like that?
0
Comment
Question by:sakthikumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Gauthier earned 500 total points
ID: 41747311
cta = new call1();
should be
this.cta = new call1();
0
 

Author Closing Comment

by:sakthikumar
ID: 41747358
Excellent Thanks:)
0
 

Author Comment

by:sakthikumar
ID: 41748255
Hi Gauthier,

If you could give me the reason for this, it would be very helpful to me.

Thanks,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question