-
Notifications
You must be signed in to change notification settings - Fork 338
-
class A {
name: String
b: Mapping<String, B>
}
class B {
name: String
}
In this simplified example, is it possible to have B.name default to the value of A.name if it's not specified? I understand the existence of the Mapping is what complicates things here, but it's at the crux of the question. It's possible I'm using the wrong type here.
Beta Was this translation helpful? Give feedback.
All reactions
If I'm interpreting your goal correctly, I think you want something like this:
class A { name: String local _a = this // this "captures" this A so it can be used unambiguously in inner scopes b: Mapping<String, B> = new { default { name = _a.name } } } class B { name: String }
So writing this:
test = new A { name = "test" b { ["abc"] {} ["def"] { name = "def" } } }
Produces
test { name = "test" b { ["abc"] { name = "test" } ["def"] { name = "def" } } }
Replies: 2 comments 1 reply
-
If I'm interpreting your goal correctly, I think you want something like this:
class A { name: String local _a = this // this "captures" this A so it can be used unambiguously in inner scopes b: Mapping<String, B> = new { default { name = _a.name } } } class B { name: String }
So writing this:
test = new A { name = "test" b { ["abc"] {} ["def"] { name = "def" } } }
Produces
test { name = "test" b { ["abc"] { name = "test" } ["def"] { name = "def" } } }
Beta Was this translation helpful? Give feedback.
All reactions
-
Ah, it was the default syntax that I didn't know of. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
-
No problem! It's worth noting that default isn't actually special syntax, it's just a regular property of the Mapping instead of a k/v entry. I wrote a little about how this all works (and link some relevant documentation) here: #1053 (comment)
Beta Was this translation helpful? Give feedback.