PageRenderTime 27ms CodeModel.GetById 24ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 50 lines | 39 code | 11 blank | 0 comment | 0 complexity | 1dea459e9aec4d22461feb690fc6fe83 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
 8	extend() is like the object() command, which
 9	creates a new bsh scripted object, except that the namespace of
10	the new object is a child of the parent object. 
11	<p>
12
13	For example:
14	<p>
15
16    <pre>
17    foo=object();
18    bar=extend(foo);
19
20    is equivalent to:
21      
22    foo() { 
23        bar() {
24            return this; 
25        }
26    }
27
28    foo=foo();
29    bar=foo.bar();
30
31    and also:
32     
33    oo=object();
34    ar=object();
35    ar.namespace.bind( foo.namespace );
36    </pre>
37	<p>
38
39	The last example above is exactly what the extend() command does.
40	In each case the bar object inherits variables from foo in the usual way.
41
42	@method This extend( This object )
43*/
44bsh.help.extend= "usage: extend( This parent )";
45extend( bsh.This parent ) 
46{
47	this.namespace.setParent( parent.namespace );
48	return this; 
49}
50