Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  95] [ 4]  / answers: 1 / hits: 18225  / 6 Years ago, fri, april 27, 2018, 12:00:00

So in C# when I've been creating model classes and lazy loading things, I do something like this:



public int? User_ID { get; set; }
public int? Dept_ID { get; set; }


Then a little farther down in my class I pop in my virtuals like so:



public virtual User User {get; set;}
public virtual Department Dept {get; set;}


How would I do this in Typescript? Something like this?:



User_ID: number;
Dept_ID: number;
User: User;
Dept: Department;


I don't think interfaces is what I want/need...but then again protected doesn't seem correct either. Something tells me I'm missing an obvious answer here.


More From » c#

 Answers
18

The following applies equally to TypeScript and JavaScript:


There is no equivalent.


Every member access in JavaScript is subject to dynamic dispatch by definition. This is because member access in JavaScript is, morally, a key lookup in a hash table.


An object may declare a member with the same key as one it inherits via the prototype chain and thereby shadow the inherited member but this is not the same as virtualness, a concept not present in the language.


[#54556] Tuesday, April 24, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
virginia

Total Points: 632
Total Questions: 95
Total Answers: 95

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;