/jEdit/tags/before-screen-line-refactoring/bsh/commands/setNameSpace.bsh

# · Unknown · 43 lines · 34 code · 9 blank · 0 comment · 0 complexity · fd12178b1694a135d3b55525d9d6738a MD5 · raw file

  1. /**
  2. Set the namespace (context) of the current scope.
  3. <p/>
  4. The following example illustrates swapping the current namespace.
  5. <p/>
  6. <pre>
  7. fooState = object();
  8. barState = object();
  9. print(this.namespace);
  10. setNameSpace(fooState.namespace);
  11. print(this.namespace);
  12. a=5;
  13. setNameSpace(barState.namespace);
  14. print(this.namespace);
  15. a=6;
  16. setNameSpace(fooState.namespace);
  17. print(this.namespace);
  18. print(a); // 5
  19. setNameSpace(barState.namespace);
  20. print(this.namespace);
  21. print(a); // 6
  22. </pre>
  23. <p/>
  24. You could use this to creates the effect of a static namespace for a
  25. method by explicitly setting the namespace upon entry.
  26. <p/>
  27. */
  28. bsh.help.setNameSpace =
  29. "usage: setNameSpace( bsh.NameSpace )";
  30. setNameSpace( ns )
  31. {
  32. // Set the namespace at depth one (our caller) to the specified namespace.
  33. this.callstack.set( 1, ns );
  34. }