PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/bsh/commands/extend.bsh

#
Unknown | 50 lines | 38 code | 12 blank | 0 comment | 0 complexity | 3fd1a11cf6787faee018b35bd0dc8c9f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. foo=object();
  26. bar=object();
  27. bar.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. }