Prototype Learning Tool Function Learning ($ w, $ F method)

Source: Internet
Author: User

$ W Method
Splits a string into an Array, treating all whitespace as delimiters. Equivalent to Ruby's % w {foo bar} or Perl's qw (foo bar ). Copy codeThe Code is as follows: function $ w (string ){
If (! Object. isString (string) return [];
String = string. strip ();
Return string? String. split (/\ s +/): [];
}

This method divides the string into arrays with blank characters and returns the result.
Example:Copy codeThe Code is as follows: $ w ('apples bananas kiwis ') //-> ['append', 'banas', 'kiwis']

$ F Method
Returns the value of a form control. This is a convenience alias of Form. Element. getValue.Copy codeThe Code is as follows: var $ F = Form. Element. Methods. getValue;
// ====> GetValue ()
GetValue: function (element ){
Element = $ (element );
Var method = element. tagName. toLowerCase ();
Return Form. Element. Serializers [method] (element );
}
// ====> Serializers
Form. Element. Serializers = {
Input: function (element, value ){
Switch (element. type. toLowerCase ()){
Case 'checkbox ':
Case 'Radio ':
Return Form. Element. Serializers. inputSelector (element, value );
Default:
Return Form. Element. Serializers. textarea (element, value );
}
},
InputSelector: function (element, value ){
If (Object. isUndefined (value) return element. checked? Element. value:
Null;
Else element. checked = !! Value;
},
Textarea: function (element, value ){
If (Object. isUndefined (value) return element. value;
Else element. value = value;
},
// Omitted. this object will be described in detail later.
......
// ====> Object. isUndefined
Function isUndefined (object ){
Return typeof object = "undefined ";
}

This function returns the value of the input parameter. From Form. element. the method defined in the Serializers object can be seen that the $ F method obtains the value of the Form element. If you define a div and call this method, the Form will be thrown. element. serializers [method] is not a function exception. If the specified ID does not exist, an element has no properties exception is thrown.
In the Form. Element. Serializers method, first check whether the value parameter exists. If it exists, it is equivalent to assigning a value to the element Parameter. If it does not exist, the element value is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.