The following describes how Prototype extends String objects:
This section mainly adds several useful methods to the string object:
Strip ():Removes the white space on both sides of the string. For example, "jj". strip () returns "jj"
StripTags ():Remove the html tag from the string.
StripScripts ():Removes the javascript code segment from the string.
ExtractScripts ():Returns the javascript code in the string and an array.
EvalScripts ():Execute the javascript code in the string
EscapeHTML ():Convert the html code in the string to a format that can be directly displayed. For example, if you convert <to <, and there is a bug in ie6, the string returned by performing this operation, multiple blank links are converted into one, so many new lines are removed.
UnescapeHTML ():Reverse process of escapeHTML
Truncate (length, truncation ):Truncation. For example, "abcdefghigkl". truncate (10) returns abcdefg..., and truncation defaults "..."ToQueryParams (separator)/parseQuery (separator ):Convert a querystring into a hash table (in fact, an object can be used as a hash table in javascript, because the object's attributes or methods can be accessed through object [propertyName)
ToArray ():Return this. split (''), converted to a character array
Camelize ():Convert the form of background-color to the form of backgroundColor and use it in style/css.
Capitalize ():Returns an uppercase string.
Inspect (useDoubleQuotes ):Returns the string representation. For example, "sdfj \" sfa ". inspect () returns" 'sdfj "sfa '"
Gsub (pattern, replacement ):Pattern is a regular expression, and replacement is a function (or a template string). replacement is used to process each part of the string that matches pattern, then replace the value returned by replacement with the original matching part, for example, "skdjfAsfdjkAdk ". gsub (/A/, function (match) {return match [0]. toLowerCase ()}) to convert all A values of the string to a. do not add the g option to pattern because gsub recursively executes the match method.
Sub (pattern, replacement, count ):Gsub is another form, but the number of executions can be set.
Scan (pattern, iterator ):Similar to gsub, but returns the string itself. That is to say, iterator is executed for each matching in pattern, but the replaced string "skdjfAsfdjkAdk" is not returned ". gsub (/A/, function () {alert 'have '})
Underscore ():'Borderbottomwidth '. underscore ()-> 'border _ bottom_width'
Dasherize ():'Hello _ world'. dasherize ()-> 'hello-world'
Template class:
Usage:
Var template = new Template (replacement, pattern );
Template. evaluate (object) is a bit like a template in php. By default (pattern is not provided), the object attribute value is replaced with the {propertyName} format.