SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Aug 3, 2007, 07:40 #1
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how to find the methods name within it
Hi,
I am stuck with this.
I wanted to evaluate a function within a method.
Code:function myfunc(){ this.func = function(param){ //code eval('this.func1');//This will not work } this.func1 = function(param){ //code } } myvar = new myfunc(); myvar.func('aa');
Please help.
-
Aug 3, 2007, 07:51 #2
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:function myfunc(){ this.func = function(param){ this.func1(param); } this.func1 = function(param){ //code } } myvar = new myfunc(); myvar.func('aa');
-
Aug 3, 2007, 07:59 #3
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that was just an example.
Actually I pass it to a Ajax function which onreadystate change should call this.func1 by evaluating it.
-
Aug 3, 2007, 08:15 #4
- Join Date
- Oct 2004
- Location
- Birtley, UK
- Posts
- 2,439
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is this a good enough example?
Code:function test1() { alert('test1 called'); } function test2(val) { alert('test2 called with param: ' + val); } function test1_call(p) { p(); } function test2_call(p, val) { p(val); } window.onload = function() { test1_call(test1); test2_call(test2, 'this is my parameter'); };
-
Aug 3, 2007, 08:25 #5
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:function myfunc(){ this.func = function(param){ //code AJAX(url, 'this.func1');//The second param is a string of the name of the callback function. It will be evaluated by AJAX onreadystate. } this.func1 = function(param){ //code } } myvar = new myfunc(); myvar.func('aa');
So i just want to know the name that 'this' will be to pass on to the AJAX Function.
-
Aug 3, 2007, 08:34 #6
- Join Date
- Nov 2005
- Location
- The Netherlands
- Posts
- 808
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why does it have to be a string? Why can't you just send the function literal as a parameter?
-
Aug 3, 2007, 09:09 #7
- Join Date
- Oct 2004
- Location
- Birtley, UK
- Posts
- 2,439
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:function test1() { alert('test1 called'); } function test2(val) { alert('test2 called with param: ' + val); } function test1_call(p) { eval(p)(); } function test2_call(p, val) { eval(p)(val); } window.onload = function() { test1_call('test1'); test2_call('test2', 'this is my parameter'); };
-
Aug 4, 2007, 03:54 #8
- Join Date
- Aug 2006
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks