Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <script src="tom.js"></script>
  2. <script src="tonny.js"></script>
  3. <script src="scott.js"></script>
  4. <script>
  5. speak();
  6. /* This will create a naming conflict as
  7. scott, tonny and tom, all use the same function */
  8. </script>
  9.  
  10. var tom = {};
  11. (function(namespace) {
  12. namespace.speak = function() {
  13. console.log("I am Tom !");
  14. };
  15. })(tom );
  16.  
  17. var tonny = {};
  18. (function() {
  19. this.speak = function() {
  20. console.log("I am Tonny !")
  21. };
  22. }).apply(tonny );
  23.  
  24. var scott = {};
  25. (function() {
  26. var speakSoftly = function() {
  27. console.log("I am Scott !")
  28. };
  29. this.speak = function() {
  30. speakSoftly();
  31. };
  32. }).call(scott );
  33.  
  34.  
  35. tom.speak();
  36. tonny.speak();
  37. scott.speak();
  38. scott.speakSoftly; // speakSoftly is local to IIFE block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement