Well, there certainly are mistakes in its design. And since it came to be, out of a pure accident, or luck, it could be much worse, that’s for sure. By far the worse mistake being its name.
But… nothing is more expressive then short and sweet JavaScript. I defy any C# “aficionado” to show me parallel to this, in her favourite language ;o)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
if ("function" !== typeof "".minus) String.prototype.minus = function( what_ ) { ///<summary> /// "ABCBDBEB".minus("B"), returns : "ACDE" /// Argument is optional, by default it is one space char /// myText.minus(), returns myText without spaces /// argument can be an regular expression /// reg.exp. given does not require 'g' or 'm' modifier /// if argument is not found in the original, the original is returned ///</summary> return (this.split(what_ || " " )).join( "" ) ; } |
That little nugget can be talked about on more “levels” than one. But, you will not be reading this if you would need this explained in greater detail, would you?
–DBJ
3 thoughts on “Is JavaScript , ok ?”
public static string minus(this string thestring, string what) {
return thestring.Replace(what ?? " ", "");
}
But that is pretty much meaningless: you could take any language and create a sample that is very well-suited to that particular language and that would be difficult to recreate in other languages. For C#, that could be a Linq-based example.
Oh wait, actually, this is even closer to your sample code:
public static string minus(this string thestring, string what = " ") {
return thestring.Replace(what, “”);
}
@Bertrand, Thanks for your comment, but. I am confused ?
Instead of imitating already not so good language, aka Java. And still not finishing the job in 10+ years, Anders H., could design and implement something better, I think. (hint: F#)
I also think that is not his fault. He was given the highly politically motivated “order”, instead of the “clean sheet” and a high degree of freedom. The “order of the day” (in 1998?) was to find and develop Sun Java & JVM “killer”. Which thankfully has been done.
Now we can perhaps admit, that we clearly see now, that at those “feverish decision-making times”, someone has decided that JavaScript was also an obvious contender, and at the same time JScript.NET was born. Only to be forever kept in the realm of the command line. Far from the headlines and centre stage of the VisualStudio, given to C#.(and sometimes VB.NET).
But this kind of “we will simply declare it as the best” attitude is curiously present inside Apple, too. The only major software developer using “Objective-C” as its “flagship” programming language. This is also very curious because of the official language of the OS-X API. Which was and is, built on C?
Strange but true …