Add String.Contains() and StringComparison enum#9
Add String.Contains() and StringComparison enum#9Gaulomatic wants to merge 2 commits intosevensc:mainfrom
Conversation
|
Good idea, but i would rather create a prototype for strings. 'this'.Contains('hi');implementation something like this. String.prototype.Contains = function (value: string): boolean {
return this.indexOf(value) !== -1;
} |
|
I thought about this as well and although (from an object orientated perspective) this makes absolute sense, I decided against it. The RxJS team also moved away from prototype manipulation. I watched a talk about this topic in the aftermath of the 6.0 release. I can't quite remember why they went this route, but from what I can tell, it can be a bit complicated to make sure to get the 'new' prototype and get IntelliSense for TypeScript. I extended the error object for an app and declared an interface. But you need to make sure, that the prototype is indeed modified, because the TS compiler won't complain (because he just don't really know). EDIT: C# has for the most part static and instance implementations as well, so you do not need to check for null beforehand. This makes the using code look cleaner. So maybe we could use both as well? It's just a preference thing at the end of the day. |
|
Could you do a test for the Contains Method? |
Hi,
I have added a static
String.Contains()method with an optional parameter of a also addedStringComparisonenum. Makes string comparisons much more C#-like.