/jEdit/tags/beanshell-1-3/bsh/commands/extend.bsh

# · Unknown · 49 lines · 38 code · 11 blank · 0 comment · 0 complexity · 8a647f506b9887a3497ac978fae78d86 MD5 · raw file

  1. /**
  2. Return a new object that is a child of the specified object.
  3. <strong>
  4. Note: this command will likely change along with a better inheritance
  5. mechanism for bsh in a future release.</strong>
  6. <p>
  7. extend() is like the object() command, which
  8. creates a new bsh scripted object, except that the namespace of
  9. the new object is a child of the parent object.
  10. <p>
  11. For example:
  12. <p>
  13. <pre>
  14. foo=object();
  15. bar=extend(foo);
  16. is equivalent to:
  17. foo() {
  18. bar() {
  19. return this;
  20. }
  21. }
  22. foo=foo();
  23. bar=foo.bar();
  24. and also:
  25. oo=object();
  26. ar=object();
  27. ar.namespace.bind( foo.namespace );
  28. </pre>
  29. <p>
  30. The last example above is exactly what the extend() command does.
  31. In each case the bar object inherits variables from foo in the usual way.
  32. @method This extend( This object )
  33. */
  34. bsh.help.extend= "usage: extend( This parent )";
  35. extend( bsh.This parent ) {
  36. this.namespace.setParent( parent.namespace );
  37. return this;
  38. }