473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

JS oop call a function whithin another function

21
Here is the example code:
Expand|Select|Wrap|Line Numbers
  1. function foo() {
  2.  
  3.     this.alert1 = function()
  4.             alert("Hello");
  5.     };
  6.  
  7.     this.alert2 = function(str){
  8.         //How can I call alert1() from here??
  9.                 !!!
  10.     };
  11. }
(Then I do: var foo = new foo();->foo.alert2 - I want it to show alert of Hello)

Any solutions?(Question in the code)
Apr 19 '11 #1

✓ answered by JKing

Hello.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <script type="text/javascript">
  4.         function foo() {
  5.  
  6.             this.alert1 = function(){
  7.                     alert("Hello");
  8.             };
  9.  
  10.             this.alert2 = function(str){
  11.                 this.alert1();
  12.             };
  13.         }
  14.     </script>
  15. </head>
  16. <body>
  17. <script type="text/javascript">
  18.     var myFoo = new foo();
  19.     myFoo.alert2();
  20. </script>
  21. </body>
  22. </html>
  23.  
You were missing an open bracket for alert1.

I added some quick markup so you can see it working.

2 1645
JKing
1,206 Expert 1GB
Hello.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <script type="text/javascript">
  4.         function foo() {
  5.  
  6.             this.alert1 = function(){
  7.                     alert("Hello");
  8.             };
  9.  
  10.             this.alert2 = function(str){
  11.                 this.alert1();
  12.             };
  13.         }
  14.     </script>
  15. </head>
  16. <body>
  17. <script type="text/javascript">
  18.     var myFoo = new foo();
  19.     myFoo.alert2();
  20. </script>
  21. </body>
  22. </html>
  23.  
You were missing an open bracket for alert1.

I added some quick markup so you can see it working.
Apr 19 '11 #2
agam
21
Thank you very much!
I didn't realize that the this keyword could be manipulated as such.
Apr 20 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: schaf | last post by:
Hi ! I'm writing a new xsl:function, which uses two other functions. But by the call of the first function, it would be abort just after the call. Not even the xsl:param would be set. I don't...
3
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
2
by: Andy Li | last post by:
I know how to call a stored procedure in SQL server from C# using SQLCommand class. Could someone tell me how to call a SQL function in SQL sever from C#? Thanks, Andy
12
by: Newbie | last post by:
how can i call an oracle function to get data without using a select statement or stored procedures? given a project_no, i need to call the function: ops$sqltime.pa_new_job_no_fn which will...
8
by: Cruella DeVille | last post by:
I'm writing a class to handle reading/writing from/to files like this (shortened) lass FileIO{ private $filename; private $mode; private $filePointer; private $dictionary; public function...
3
by: balakrishnan.dinesh | last post by:
hi frndz, I need to call a C program function from php code, Is that possible, If it is ,then tell me how ? i.e,main() { int callfunction(); int i=2; callfunction(i); } callfucntion(int i)
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
8
by: ManicQin | last post by:
Hi lets say I have the next situation class base { pubic: ;) base() {} virtual ~base(){} virtual init() {//do init } };
2
by: kasukur | last post by:
Hi i am new to .net. Can someone please advise how to call a SQL function which returns a cursor using c# i have tried to call using OracleCommand.CommandType = CommandType.StoredProcedure ...
3
by: anis0408 | last post by:
How can I call a C function from php (with argmts)? In fact, I just need to call a C function which is in a library. I tried this : system('rundll32.exe library.dll,function 20 '); I can call...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.