Post a Reply
12814 views

Method overloading

  1. 4 years ago

    marco

    Show in context Administrator User since 2016

    If you want to be safe for future language improvements then you can write:

    class Person {
    	var _age
    	var _name 
    	
    	func SetDefaults(name = "John Doe" , age = 0) {
    		 if (name) _name = name
    		if (age) _age = age	
    	}
    }

    please note that instead of SetDefaults you could have an init function (the constructor) so your code will be much more easier to read. There is a small bug in the init constructor (when called with a different number of arguments) so you should wait few days for the next upcoming release.

  2. Marc

    Show in context User since 2018
    Edited 4 years ago by Marc

    @marco If you want to be safe for future language improvements then you can write:

    Ah ok, just like optionals in C#.

    @marco please note that instead of SetDefaults you could have an init function

    Yes I know. This was just an example.

    @marco There is a small bug in the init constructor (when called with a different number of arguments)

    I know, I did experience that bug today already ... ;)