SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Pass function through another...
Hybrid View
-
Apr 11, 2007, 06:35 #1
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pass function through another...
wasn't sure how to write the subject, but here's what i want...
Code:function myFunction(text, number, action) { // stuff action; // more stuff } function anotherFunction(message) { alert(message); } function yetAnotherFunction(message) { confirm(message); } myFunction("sometext", 9, anotherFunction());
-
Apr 11, 2007, 07:53 #2
- Join Date
- Nov 2006
- Posts
- 68
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use the call method as show in the code below to do this
function myFunction(text, number, action) {
action.call(this, text, number);
};
function anotherFunction(message) {
alert(message);
};
function yetAnotherFunction(message) {
confirm(message);
};
myFunction("sometext", 9, yetAnotherFunction);
-
Apr 11, 2007, 08:12 #3
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
awesome...that's the little thing i was missing. appreciated.
-
Apr 11, 2007, 08:17 #4
- Join Date
- Apr 2007
- Location
- UK, soon in USA
- Posts
- 27
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
try this...
Code:function myFunction(text, action) { // stuff return action(text); // more stuff } function anotherFunction(message) { alert(message); } function yetAnotherFunction(message) { return confirm(message); } // The alert version myFunction("sometext1", anotherFunction); // The confirm version if(myFunction("sometext2", yetAnotherFunction)) alert("yo"); else alert("cya"); // Anon function... myFunction("sometext3", function(thing){ alert(thing); });
Matt "Moridin8" Warren
======================================
Website: www.csharp-architect.com
....IRC: Usually freenode... '##csharp'
Bookmarks