PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/extend.bsh

#
Unknown | 50 lines | 39 code | 11 blank | 0 comment | 0 complexity | 1dea459e9aec4d22461feb690fc6fe83 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. 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. {
  37. this.namespace.setParent( parent.namespace );
  38. return this;
  39. }