Skip to content

Self reference a callable constructor argument

rollynoel edited this page Jun 13, 2013 · 2 revisions

Added by Bill Wood

Sometimes its useful to allow a self reference (to an object being created) in a callable constructor argument. If you try this you will get an "Unknown identifier" error; so declare the object before instantiating it:

class X:
	public f as callable() as string	// f must be public to be called from a passed-in closure
	public s = "hello"
	def constructor(f as callable() as string):
		self.f = f

a as X		// declare it first!
a = X({ return a.s })
print a.f()
Clone this wiki locally