Guest User

Untitled

a guest
Jan 22nd, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. //-------------------------------------------------------------
  2. // your-company.js
  3.  
  4. window.yourCompany = {
  5. version: '1.0',
  6. namespace: function(path) {
  7. var part,
  8. currentObject = window,
  9. parts = path.split('.')
  10. ;
  11. for (var i=0, len=parts.length; i < len; i++) {
  12. part = parts[i];
  13. if (!currentObject.hasOwnProperty(part)) {
  14. currentObject[part] = {};
  15. }
  16. currentObject = currentObject[part];
  17. }
  18. return currentObject;
  19. }
  20. };
  21.  
  22. //-------------------------------------------------------------
  23. // your-company/ui/wizzle.js
  24.  
  25. (function() {
  26. var ns = yourCompany.namespace('yourCompany.ui.wizzle');
  27. ns.defaultSize = 'tall';
  28. })();
  29.  
  30. //-------------------------------------------------------------
  31. // Console
  32.  
  33. console.log(yourCompany.version); // -> 1.0
  34. console.log(yourCompany.ui.wizzle.defaultSize); // -> tall
  35. console.log(window.ns); // -> undefined
Add Comment
Please, Sign In to add comment