Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var func1 = function() {
  2. // console.log(this.source1); // wont work, makes sense
  3. // console.log(source1); // wont work, wish it would
  4. console.log(this.source2); // works fine
  5. console.log(source2); // works fine
  6. };
  7. var func2 = function() {
  8. var source1 = "source1";
  9. this.source2 = "source2";
  10. func1.call(this);
  11. }();
  12. var func3 = function() {
  13. var source3 = "source3";
  14. var func4 = function() {
  15. console.log(source3); // also works fine, makes sense
  16. }();
  17. }();
  18.  
  19. var module = (function() {
  20. var source1;
  21. var source2;
  22.  
  23. var func1 = function() {
  24. console.log(source2); // works fine
  25. };
  26. var func2 = function() {
  27. source1 = "source1";
  28. }();
  29. var func3 = function() {
  30. var func4 = function() {
  31. console.log(source1); // also works fine, makes sense
  32. }();
  33. }();
  34.  
  35. return {
  36. func1: func1,
  37. func2: func2,
  38. func3: func3
  39. };
  40.  
  41. }());
  42.  
  43. // Then invoke them.
  44. module.func2();
  45. module.func1();
  46.  
  47. var func1 = module.func1;
  48. var func2 = module.func2;
  49. var func3 = module.func3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement