Fundamentally, can the "this" keyword be the same in C# vs Javascript

I am getting into a fundamental argument about strongly typed, and statically typed languages. The other debater is a pure javascript enthusiast. While I enjoy working with both c# and javascript. The conversation arose over the discussion about TypeScript and how it’s better than pure js because it is strongly typed. (subjective already). So I provided him with an argument that TypeScript already fails at what it is attempting to do with the following example.

class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

var greeter = new Greeter("world");
var greetWorld = greeter.greet;
alert(greetWorld()); //undefined, unexpected for strongly typed languages

I have already said this is expected in JS. In fact, I love this. This is why it being a dynamically typed language is so powerful. But, the ‘this’ keyword is nothing more than a property in JS and why TypeScript is just an additional layer adding to confusion and making it no better.

“When a function is created, a keyword called this is created (behind the scenes), which links to the object in which the function operates.”(JS).

Well this is truly just a property of the function/object then. The definition of strongly typed: ” each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.” So the data-type function/object are separate, keyword “ONE” of the data types.

I just can’t seem to drive the argument home. In fact, I might even be wrong. To me though, the problem above is a runtime type error, that their is no greeting even though it should be expected if the ‘this’ keyword were truly bound in the programming language.

Am I missing something?

139 thoughts on “Fundamentally, can the "this" keyword be the same in C# vs Javascript”

  1. Skribbl.io game is an online drawing and word guessing game also free. The game consists of several rounds where each round has to draw the chosen word, and other players in the game have to guess the word to score points. This game is one of the best educational games exciting, and it will help you increase your IQ level. The player with the most points will be declared the winner at the end of the game. Many different languages ​​are available in the game, so players can improve their vocabulary by choosing the language they want to play the game in. The game’s name is derived from the scribble that you write in a hurry and draw something fast.

    Reply
  2. Royalcasino Üyelik Kuralları Royalcasino bahis sitesine dahil olmak isteyen çok sayıda kişi bulunmaktadır. Site içerisinde yer alan kampanyalar ve fırsatlar nedeniyle siteye dahil olmak isteyen çok sayıda kişi bulunur. Bu tutumu ve kampanyaları nedeniyle kullanıcı sayısı her geçen gün artmaktadır. Kullanıcı sayısı her geçen gün artan bu siteye dahil olmak için yapmanız gereken tek şey üyelik formunu doldurmaktır. Site içerisinde yer alan formu doldurmadan önce 18 yaşından büyük olmanız gerekmektedir. Ayrıca başkasının bilgileriyle üye olmak kesinlikle yasaktır. Bu bilgi daha sonra geri alınamaz. Dolayısıyla ilerleyen zamanlarda farklı bilgilerle üye olan kişiler kendi hesabına çekim yapamayabilir. Royalcasino bahis sitesi için bu şartları karşılıyorsanız üye olmanız için bir engel yok demektir.

    Reply

Leave a Comment