What does this colon (:) mean?

It (along with the this keyword) is instructing the constructor to call another constructor within the same type before it, itself executes. Therefore: public ListNode(object dataValue) : this(dataValue, null) { } effectively becomes: public ListNode(object dataValue) { data = dataValue; next = null; } Note that you can use base instead of this to instruct …

Read more

How does `this` reference to an outer class escape through publishing inner class instance?

Please see this article. There it’s clearly explained what could happen when you let this escape. And here is a follow-up with further explanations. It’s Heinz Kabutz amazing newsletter, where this and other very interesting topics are discussed. I highly recommend it. Here is the sample taken from the links, which show how the this …

Read more

Call constructor on TypeScript class without new

What about this? Describe the desired shape of MyClass and its constructor: interface MyClass { val: number; } interface MyClassConstructor { new(val: number): MyClass; // newable (val: number): MyClass; // callable } Notice that MyClassConstructor is defined as both callable as a function and newable as a constructor. Then implement it: const MyClass: MyClassConstructor = …

Read more