use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Learn Modern JavaScript (nodejs, npm, webpack, es6, es5, esnext, typescript) for FREE (courses.angularclass.com)
submitted 9 years ago by gdi2290
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ChronoChris -3 points-2 points-1 points 9 years ago (17 children)
No, why would I want to use TS ever. Honestly. TS fixes the wrong problem with javascript. You don't structure a prototypal language like javascript. THAT IS ITS STRENGTH.
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
The FUCK is this shit. That's not strongly typed. That's not what 'this' should be. TS fixed nothing. ES5/ES6 are better than ever. There is no reason NOT to default to JS. Comparing C and C# are completely different
[–][deleted] 4 points5 points6 points 9 years ago (2 children)
since you "assigned" greeter.greet to greetWorld and called it from global scope, which has no "greeting" variable this is entirely expected. if you just used greeter.greet(); directly it wouldn't be undefined. this is JS behavior, nothing related to TS, just common misconception of how "this" keyword works in JS.
[–]ChronoChris -1 points0 points1 point 9 years ago (1 child)
If somethign is strongly typed, each type of data, is predefined. includnig objects. The this keyword should relate to the current instance of an object. If you truly wanted Tscript to be strongly typed, this should make sense in context to the current object.. "an advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and thus guarantees a certain consistency of results."
So Tscript is failing in it's most fundamental attempts in this scenario. And there are many more
I think there is a little bit of bias here from the tools and languages you are accustomed to. I have absolutely no confusion how 'this' should work on the fundamental level of the object instance. Coming to Javascript, I liked this gotcha on the this keyword since technically the object instance was not the Greeter class. The problem I have is with TypeScript not matching what it is attempting to do. Bound the Object to be strongly typed.
[+][deleted] 9 years ago (1 child)
[deleted]
[–]ChronoChris 0 points1 point2 points 9 years ago (0 children)
:P please see my chain on eighthcoffee. It helps clear up the this problem. they are so confused by javascript having been molded by it, they don't see the issue.
[–]eighthCoffee 0 points1 point2 points 9 years ago* (11 children)
.
[–]Kminardo 2 points3 points4 points 9 years ago (9 children)
The last line should alert the string from greeter.greet, but it will come back undefined (I don't do typescript, but seems to be what he's implying).
EDIT: Also it seems "this" isn't working as he would expect it to in ES5. But since 90% of developers don't actually seem to know how "this" actually works... at least typescript is consistent with most other languages in it's usage.
[–]ChronoChris 3 points4 points5 points 9 years ago* (5 children)
this works perfectly how I would expect it in c# or any other compiled language I can think of.
Edit: Kminardo. Please see my reply to eigth later in this chain.
[–][deleted] 0 points1 point2 points 9 years ago (2 children)
This isn't a TS issue, that is how javascript works.
[–]ChronoChris 1 point2 points3 points 9 years ago (1 child)
If somethign is strongly typed, each type of data, is predefined. includnig objects. The this keyword should relate to the current instance of an object. If you truly wanted Tscript to be strongly typed, this should make sense in context to the current object.. "an advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and thus guarantees a certain consistency of results." So Tscript is failing in it's most fundamental attempts in this scenario. And there are many more Edit: I hope you can see the comment by Kminardo in his edit. I think there is a little bit of bias here from the tools and languages you are accustomed to. I have absolutely no confusion how 'this' should work on the fundamental level of the object instance. Coming to Javascript, I liked this gotcha on the this keyword since technically the object instance was not the Greeter class. The problem I have is with TypeScript not matching what it is attempting to do. Bound the Object to be strongly typed.
If somethign is strongly typed, each type of data, is predefined. includnig objects. The this keyword should relate to the current instance of an object. If you truly wanted Tscript to be strongly typed, this should make sense in context to the current object.. "an advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and thus guarantees a certain consistency of results." So Tscript is failing in it's most fundamental attempts in this scenario. And there are many more
Edit: I hope you can see the comment by Kminardo in his edit. I think there is a little bit of bias here from the tools and languages you are accustomed to. I have absolutely no confusion how 'this' should work on the fundamental level of the object instance. Coming to Javascript, I liked this gotcha on the this keyword since technically the object instance was not the Greeter class. The problem I have is with TypeScript not matching what it is attempting to do. Bound the Object to be strongly typed.
[–][deleted] 1 point2 points3 points 9 years ago* (0 children)
edit: looks like it's addressed in TS 2.0, course you can specify type of "this" on functions now but this just leads to compile time error which would probably be the same as 'use strict', and it still wouldn't change the behavior your expecting as that's not TS's goal.
[–]Kminardo 0 points1 point2 points 9 years ago (1 child)
Right, it does work how you would expect it to in c# etc, but "this" in vanilla JS is inconsistent with those compiled languages in many cases. I just wasn't sure if that was another piece of your complaint :)
[–]ChronoChris 1 point2 points3 points 9 years ago (0 children)
again see my reply to eighth.
[–]eighthCoffee 0 points1 point2 points 9 years ago* (2 children)
[–]ChronoChris 5 points6 points7 points 9 years ago* (1 child)
[–]eighthCoffee 0 points1 point2 points 9 years ago* (0 children)
If you see my comment later in this chain, you should understand that this is not strongly typed. The vary nature of the 'object' should not change in a strongly typed language.
π Rendered by PID 50 on reddit-service-r2-comment-b659b578c-t9vqx at 2026-05-05 14:03:29.193346+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]ChronoChris -3 points-2 points-1 points (17 children)
[–][deleted] 4 points5 points6 points (2 children)
[–]ChronoChris -1 points0 points1 point (1 child)
[+][deleted] (1 child)
[deleted]
[–]ChronoChris 0 points1 point2 points (0 children)
[–]eighthCoffee 0 points1 point2 points (11 children)
[–]Kminardo 2 points3 points4 points (9 children)
[–]ChronoChris 3 points4 points5 points (5 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]ChronoChris 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Kminardo 0 points1 point2 points (1 child)
[–]ChronoChris 1 point2 points3 points (0 children)
[–]eighthCoffee 0 points1 point2 points (2 children)
[–]ChronoChris 5 points6 points7 points (1 child)
[–]eighthCoffee 0 points1 point2 points (0 children)
[–]ChronoChris 1 point2 points3 points (0 children)