/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
- /**
- Return a new object that is a child of the specified object.
- <strong>
- Note: this command will likely change along with a better inheritance
- mechanism for bsh in a future release.</strong>
- <p>
- extend() is like the object() command, which
- creates a new bsh scripted object, except that the namespace of
- the new object is a child of the parent object.
- <p>
- For example:
- <p>
- <pre>
- foo=object();
- bar=extend(foo);
- is equivalent to:
-
- foo() {
- bar() {
- return this;
- }
- }
- foo=foo();
- bar=foo.bar();
- and also:
-
- oo=object();
- ar=object();
- ar.namespace.bind( foo.namespace );
- </pre>
- <p>
- The last example above is exactly what the extend() command does.
- In each case the bar object inherits variables from foo in the usual way.
- @method This extend( This object )
- */
- bsh.help.extend= "usage: extend( This parent )";
- extend( bsh.This parent )
- {
- this.namespace.setParent( parent.namespace );
- return this;
- }