Created
June 13, 2018 00:45
-
-
Save joegaudet/570dab58852712d2990506b7170a2c82 to your computer and use it in GitHub Desktop.
optional-interfaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
def doIt(foo:Int, bar:Option[Foo] = None):Int { | |
foo + bar.getOrElse(0) | |
} | |
} | |
// returns 1 | |
new Foo().doIt(1) | |
// returns 3 | |
new Foo().doIt(1, Some(2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
doIt(a: number, b?: number): number { | |
b = b || 0 | |
return a + b; | |
} | |
} | |
// prints 1 | |
console.log(new Foo().doIt(1)) | |
// prints 3 | |
console.log(new Foo().doIt(1, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment