Solved

javascript passing a function

Posted on 2014-01-21
1
248 Views
Last Modified: 2014-01-21
I have the following code here.  My question is how would i pass a function within a function. Is it even possible  

var say ={

    hello:function(saywhat,passfunction){
      console.log(saywhat);
    }
    
}

Open in new window

0
Comment
Question by:stargateatlantis
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
why not?

var say = {

    hello:function(saywhat, passfunction){
      passfunction();
      console.log(saywhat);
    }
   
}

say.hello("world", function() { console.log("hello");  })

var myFct = function() { console.log("hello");  }
say.hello("world", myFct)

function fct() { console.log("hello");  }
say.hello("world", fct)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now