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 })