Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //init test object /create namespace
  2. var test = window.test = {
  3. display : {},
  4. utils : {}
  5. };
  6.  
  7.  
  8. test.display = new function display(){ // create a singleton of the display object
  9. var utils = test.utils; // create an alias
  10. this.show = function(){
  11. return utils.sayHello(); // but the alias doesn't work, utils is an empty object
  12. // test.utils.sayHello() works perfectly
  13. };
  14. };
  15.  
  16. test.utils = new function utils() { // create a singleton of the utils object
  17. this.sayHello = function(){
  18. alert('hello');
  19. };
  20. };
  21.  
  22. test.display.show();
Add Comment
Please, Sign In to add comment