ExtJs -- 13 -- Ext. apply (src, apply) and Ext. applyIf (src, apply)

Source: Internet
Author: User

ExtJs -- 13 -- Ext. apply (src, apply) and Ext. applyIf (src, apply)

Ext. onReady (function () {/** Ext. apply (src, apply) and Ext. comparison between the use and difference of applyIf (src, apply) Methods * // Ext. the apply (src, apply) method is used to extend and modify the attributes or methods of the original object. // defines the object srcvar src = {name: "tom", age: 22 }; // define the object applyvar apply = {sex: "male", age: 33, name: "jack", sal: 10000}; // use Ext. the apply method extends the attributes or methods of src objects. apply (src, apply); // view multiple attributes and attribute values of src for (var attr in src) {document. write (attr + "--" + src [attr]) document. write ("
")} // The result is as follows // name -- jack // age -- 33 // sex -- male // sal -- 10000 // you can see from the source code and test results: // compare the attributes in the apply object with those in the src object one by one. If this attribute does not exist in the src object, the values are assigned to the src object. If the property has the same attribute, overwrite the original attribute value // Ext. after the apply method is expanded, the result is the above test result ********* * ************* document. write ("
") // Ext. applyIf (src, apply) and Ext. the difference between apply (src, apply) and apply is that // if the original object has an attribute that is currently being compared, no replication will be performed, of course, the attribute value will not be modified. // For example: var srcif = {name: "tom", age: 22}; var applyif = {sex: "male ", age: 33, name: "jack", sal: 10000}; Ext. applyIf (srcif, applyif); for (var attr in srcif) {document. write (attr + "----" + srcif [attr]) document. write ("
")} // The result is // name ---- tom // age ---- 22 // sex ---- male // sal ---- 10000 })

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.