Javascript prototype is very useful thing. Say, we want to perform some sort of transformation or something else on string like we want to find some pattern matching for validation. Example below is based on this.
Requires: Javascript
Using:
Requires: Javascript
Using:
Explanation:
Line 2: We created a prototype object for string named found and equate it to null.
Then in the code below it we find the pattern 'str' insensitive of case.
Line 3: We create str as String.
Line 17: Then we gave value to 'found' which can be used further.
Note: Line 3 is important here as prototype for String is given, so str = 'my string' will not work. We have to declare it as String type. Same is to be done if it is being used with other type or custom types.
No comments:
Post a Comment
Thank you for your comment!