Instantiate a class and immediately call methods

Monkey Forums/Monkey Programming/Instantiate a class and immediately call methods

frank(Posted 2012) [#1]
I am wondering why this is not working:

assets = New Assets().LoadAssets()

I think it would be rather a good idea to make this work if there is no good reason to not make it work; I think it does in most other OO languages and it's handy to chain stuff (as good practice setters/actions should return Self so you can do stuff like:

New Assets().LoadAssets().SetPrimary('bla').DoSomething()

and so on and so forth)

Edit: you can remove this post.. Must be the eggnog, this *Does* work. Sorry :)


Samah(Posted 2012) [#2]
That will only work if LoadAssets(), SetPrimary() and DoSomething() each return Self (or any instance of Assets).