JS callback function


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function test(f){
  2. var x = 'private var';
  3. if (typeof f == "function") f(x); else alert('no callback');
  4. }
  5.  
  6.  
  7. test(function(x){
  8. alert(x)
  9. })
  10.  
  11.  
  12. //////////
  13. function test2(){
  14. var x = 'private var';
  15. return x
  16. }
  17.  
  18. var result = test2(); // = x

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.