PageRenderTime 80ms CodeModel.GetById 78ms app.highlight 0ms RepoModel.GetById 1ms 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
 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
18		foo=object();
19		bar=extend(foo);
20
21	is equivalent to:
22	  
23		foo() { 
24			bar() {
25				return this; 
26			}
27		}
28
29		foo=foo();
30		bar=foo.bar();
31
32	and also:
33	 
34	   foo=object();
35	   bar=object();
36	   bar.namespace.bind( foo.namespace );
37	</pre>
38	<p>
39
40	The last example above is exactly what the extend() command does.
41	In each case the bar object inherits variables from foo in the usual way.
42
43	@method This extend( This object )
44*/
45bsh.help.extend= "usage: extend( This parent )";
46extend( bsh.This parent ) { 
47	this.namespace.setParent( parent.namespace );
48	return this; 
49}
50