Is it possible to typedef things in javascript somehow? Maybe by getting it from the prototype object or something?
For instance, i’d like to typedef the var keyword.
var string = prototype.var;
So now in stead of using ‘var’ i can use:
string blaat = "It's like using the 'var' keyword";
Is this possible somehow in javascript?
No, this is not possible. Period.
Your example is also an impossible thing to want, even though I understand the motivation. JavaScript is dynamically typed. You cannot declare variables to be string. And in that light the whole statement
string x = "foo";is pointless.EDIT Yes, it’s possible to achieve this effect with TypeScript. No, TypeScript is not JavaScript. The question was about the latter. That you can do a similar thing in a completely different programming language does not make this answer incorrect or obsolete.
Declaring a variable as, e.g.,
stringwill remain impossible in JavaScript until the day when the ECMAScript Standard adds static typing to the language.