Guest User

Untitled

a guest
Jun 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. var MYGLOBALS = function() {
  2. var globals = {
  3. foo : "bar",
  4. batz : "blah"
  5. }
  6. return { getValue : function(s) {
  7. return globals[s];
  8. }
  9. }
  10. }();
  11. alert(MYGLOBALS.getValue("foo")); // returns "bar"
  12. alert(MYGLOBALS.getValue("notthere")); // returns undefined
  13. MYGLOBALS.globals["batz"] = 'hardeehar'; // this will throw an exception as it should
  14.  
  15. var myLibName = (function() {
  16. var aPrivateVar;
  17.  
  18. function aPrivateFunction() {}
  19.  
  20. function accessorForPrivateVar() {
  21. return aPrivateVar;
  22. }
  23.  
  24. // public interface:
  25. return {
  26. getPrivateVar : accessorForPrivateVar
  27. }
  28. })();
  29.  
  30. var CONSTANTS = function() {
  31. var constants = { } ; //Initialize Global Space Here
  32. return {
  33. defineConstant: function(name,value)
  34. {
  35. if(constants[name])
  36. {
  37. throw "Redeclaration of constant Not Allowed";
  38. }
  39. },
  40. getValue(name)
  41. {
  42. return constants[name];
  43. }
  44. } ;
  45. }() ;
  46. CONSTANTS.defineConstant('FOO','bar') ;
  47. print(CONSTANTS.getValue('FOO')) ; //Returns bar
  48. CONSTANTS.defineConstant('FOO','xyz') ; // throws exception as constant already defined
  49. CONSTANTS.getValue('XYZ') ; //returns undefined
  50.  
  51. const whatEver = 'Hello World!!!';
  52.  
  53. function foo(value){
  54. whatEver = value;
  55. }
  56.  
  57. <div onclick="foo('New Value');">Change Me First</div>
  58. <div onclick="alert(whatEver);">Then click me After: Should Be alert "Hello World!!!"</div>
  59.  
  60. const yourVar = 'your value';
  61.  
  62. navigator.pleaseDontChangeThis = 25;
  63.  
  64. // 'val' can be a string, integer, hash table, array, object
  65. $.secret( 'in', 'secretName', val );
  66.  
  67. // or a function
  68. $.secret( 'in', 'secretName', function( arg1, arg2, arg3 ){
  69. // do something here
  70. });
  71.  
  72. var lang = $.secret( 'out', 'lang' );
  73.  
  74. $.secret( 'call', 'secretName', [ arg1, arg2, arg3 ]);
  75. // or
  76. $.secret( 'call', 'secretName', arg );
  77.  
  78. $.secret( 'clear', 'lang' );
  79.  
  80. private var myGlobal : myType;
  81. function GetMyGlobal() : myType
  82. {
  83. return myGlobal;
  84. }
Add Comment
Please, Sign In to add comment