Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MYGLOBALS = function() {
- var globals = {
- foo : "bar",
- batz : "blah"
- }
- return { getValue : function(s) {
- return globals[s];
- }
- }
- }();
- alert(MYGLOBALS.getValue("foo")); // returns "bar"
- alert(MYGLOBALS.getValue("notthere")); // returns undefined
- MYGLOBALS.globals["batz"] = 'hardeehar'; // this will throw an exception as it should
- var myLibName = (function() {
- var aPrivateVar;
- function aPrivateFunction() {}
- function accessorForPrivateVar() {
- return aPrivateVar;
- }
- // public interface:
- return {
- getPrivateVar : accessorForPrivateVar
- }
- })();
- var CONSTANTS = function() {
- var constants = { } ; //Initialize Global Space Here
- return {
- defineConstant: function(name,value)
- {
- if(constants[name])
- {
- throw "Redeclaration of constant Not Allowed";
- }
- },
- getValue(name)
- {
- return constants[name];
- }
- } ;
- }() ;
- CONSTANTS.defineConstant('FOO','bar') ;
- print(CONSTANTS.getValue('FOO')) ; //Returns bar
- CONSTANTS.defineConstant('FOO','xyz') ; // throws exception as constant already defined
- CONSTANTS.getValue('XYZ') ; //returns undefined
- const whatEver = 'Hello World!!!';
- function foo(value){
- whatEver = value;
- }
- <div onclick="foo('New Value');">Change Me First</div>
- <div onclick="alert(whatEver);">Then click me After: Should Be alert "Hello World!!!"</div>
- const yourVar = 'your value';
- navigator.pleaseDontChangeThis = 25;
- // 'val' can be a string, integer, hash table, array, object
- $.secret( 'in', 'secretName', val );
- // or a function
- $.secret( 'in', 'secretName', function( arg1, arg2, arg3 ){
- // do something here
- });
- var lang = $.secret( 'out', 'lang' );
- $.secret( 'call', 'secretName', [ arg1, arg2, arg3 ]);
- // or
- $.secret( 'call', 'secretName', arg );
- $.secret( 'clear', 'lang' );
- private var myGlobal : myType;
- function GetMyGlobal() : myType
- {
- return myGlobal;
- }
Add Comment
Please, Sign In to add comment