Prototype Learning tool function Learning ($w, $F method) _prototype

Source: Internet
Author: User
$w method
Splits a string into the Array, treating all whitespace as delimiters. Equivalent to Ruby ' s%w{foo bar} or Perl ' s QW (foo bar).
Copy Code code as follows:

function $w (string) {
if (! Object.isstring (String)) return [];
string = String.strip ();
return string? String.Split (/\s+/): [];
}

The method is to divide the string into an array with whitespace characters and then return.
Example:
Copy Code code as follows:

$w (' Apples bananas Kiwis ')//-> [' apples ', ' bananas ', ' Kiwis ']

$F method
Returns the value of a form control. This is a convenience alias of Form.Element.getValue.
Copy Code code 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, in the future when speaking of this object in detail
......
====> object.isundefined
function isundefined (object) {
Return typeof object = = "undefined";
}

This function finally returns the value of the passed-in parameter. The method defined from the Form.Element.Serializers object shows that the $F method gets the value of the form element, and if you define a div and then call this method, it throws the Form.element.serializers[method ' Is ' not ' a function exception, which will throw the element has no properties exception if the given ID does not exist.
The method inside the Form.Element.Serializers first checks whether the value of this parameter exists, the existence is equivalent to assigning a value to the element parameter, and does not exist will return the value of element

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.