Ext JS expands native javascript Objects Based on Ext On the ninth day
ExtJS extends native Javascript-Ext.Object-Ext.Number-Ext.String-Ext.Array-Ext.Function-Ext.Date-Ext.Error -------------------------------------------------------------------------------- Ext. object no.1 chain (Object object) Copying code // Ext extensions for native javascript objects // Ext. object // 1: The chain regards the currently passed Object as a new Object. The prototype var obj = {name: 'z3', age: 10}; var result = Ext. object. chain (obj); alert (result. name); // z3 alert (result. age); // 10 alert (result. hasOwnProperty ('name'); // false hasOwnProperty () is used to determine whether an attribute is owned by itself. If false is returned, the name attribute is not owned by obj; obj is the prototype Object of result copy Code No. 2 each (object Object, Function fn, [Object scope]) Copy code // 2: the current object of the each variable is destroyed and three attributes key, value, and self are exposed in the function. If the callback function returns false, the iteration var obj = {name: 'zhang san' is stopped. age: 20, Sex: 'male'}; Ext. object. each (obj, function (key, value, self) {alert (key + ':' + value); if (age = 20) {return false ;}}); copy the code no.3fromQueryString (String queryString, [Boolean recursive]): the Object converts the query String back to the Object.... Ext. object. fromQueryString ("foo = 1 & bar = 2"); // returns {foo: 1, bar: 2} Ext. object. fromQueryString ("foo = & bar = 2"); // returns {foo: null, bar: 2} Ext. object. fromQueryString ("some % 20 price = % 24300"); // {'some price': '$300'} Ext. object. fromQueryString ("colors = red & colors = green & colors = blue"); // return {colors: ['red', 'green ', 'blue']} copy the code Ext. object. fromQueryString ("username = Jacky &" + "dateOfBirth [day] = 1 & dateOfB Irth [month] = 2 & dateOfBirth [year] = 1911 & "+" hobbies [0] = coding & hobbies [1] = eating & hobbies [2] = sleeping & "+ "hobbies [3] [0] = nested & hobbies [3] [1] = stuff ", true); // returns {username: 'jacky', dateOfBirth: {day: '1', month: '2', year: '20140901'}, hobbies: ['coding', 'eating ', 'sleeping', ['nested', 'stuff ']} copy Code No. 4 getKey (Object object Object, Object value) var person = {name: 'jacky', loves: 'food'}; alert (Ext. obje Ct. getKey (person, 'food'); // The 'loves 'no. 5 toQueryObjects (String name, Object/Array value, [Boolean recursive]): Array converts a name-value pair to an Object Array and supports internal structure conversion, it is very useful for constructing query strings. Example: copy the code var objects = Ext. object. toQueryObjects ('jobbies', ['reading', 'cooking', 'canonicals']); // objects equals to [{name: 'jobbies', value: 'reading'}, {name: 'hobbies', value: 'cooking'}, {name: 'hobbies', value: 'shaping'},]; var objects = Ext. object. toQueryObjects ('dateofbirth ', {day: 3, month: 8, year: 1987, extra: {hour: 4 minute: 30 }}, true ); // recursion // objects equals to [{name: 'dateofbir Th [day] ', value: 3}, {name: 'dateofbirth [month]', value: 8}, {name: 'dateofbirth [year] ', value: 1987}, {name: 'dateofbirth [extra] [hour] ', value: 4}, {name: 'dateofbirth [extra] [minute]', value: 30},]; copy Code No. 6 getKeys (Object object): String [] to obtain the array var values = Ext. object. getKeys ({name: 'jacky', loves: 'food'}); // ['name', 'loves '] NO. 7 getSize (Object object): Number Number of all self-owned attributes var size = Ext. object. getSize ({name: 'jacky', loves: 'food'}); // size equals to 2 no. 8 getValues (Object object Object): Array obtains an Array composed of all values of a given object. Var values = Ext. object. getValues ({name: 'jacky', loves: 'food'}); // ['jacky', 'food'] No. 9 merge (Object destination, Object... object): recursively merges any number of objects, but does not reference them or their sub-objects. Check the copy code var extjs = {companyName: 'ext js', products: ['ext js', 'ext GWT ', 'ext Designer'], isSuperCool: true, office: {size: 2000, location: 'palo Alto ', isFun: true }}; var newStuff = {companyName: 'sencha Inc. ', products: ['ext js', 'ext GWT', 'ext Designer ', 'sencha touch', 'sencha animator'], office: {size: 40000, location: 'redwood City'}; var sencha = Ext. object. merge (extjs, newStuff); // Extjs and sencha are equal to {companyName: 'sencha Inc. ', products: ['ext js', 'ext GWT', 'ext Designer ', 'sencha touch', 'sencha animator'], isSuperCool: true, office: {size: 40000, location: 'redwood city', isFun: true} copy Code No. 10 toQueryObjects (String name, Object/Array value, [Boolean recursive]): Array to give an example: copy the code var objects = Ext. object. toQueryObjects ('jobbies', ['reading', 'cooking', 'describe' ]); // Objects equals to: [{name: 'jobbies', value: 'reading'}, {name: 'jobbies', value: 'cooking '}, {name: 'hobbies ', value: 'canonicalization'},]; var objects = Ext. object. toQueryObjects ('dateofbirth ', {day: 3, month: 8, year: 1987, extra: {hour: 4 minute: 30 }}, true ); // recursion // objects equals to: [{name: 'dateofbirth [day] ', value: 3}, {name: 'dateofbirth [month]', value: 8 }, {name: 'dateofbirth [year] ', Value: 1987}, {name: 'dateofbirth [extra] [hour] ', value: 4}, {name: 'dateofbirth [extra] [minute]', value: 30},]; copy Code No. 11 toQueryString (Object object, [Boolean recursive]): String converts an Object into an encoded query String. Copy the code without recursion: Ext. object. toQueryString ({foo: 1, bar: 2}); // return "foo = 1 & bar = 2" Ext. object. toQueryString ({foo: null, bar: 2}); // return "foo = & bar = 2" Ext. object. toQueryString ({'some price': '$300'}); // return "s Ome % 20 price = % 24300 "Ext. object. toQueryString ({date: new Date (2011, 0, 1)}); // return "date = % 222011-01-01T00% 3A00% 3A00% 22" Ext. object. toQueryString ({colors: ['red', 'green', 'blue']}); // return "colors = red & colors = green & colors = blue" recursion: ext. object. toQueryString ({username: 'jacky', dateOfBirth: {day: 1, month: 2, year: 1911}, hobbies: ['coding', 'eating ', 'sleeping ', ['nested ', 'stuff']}, true); // return the following characters: String (line feed and url-decoded are for ease of reading ): // username = Jacky // & dateOfBirth [day] = 1 & dateOfBirth [month] = 2 & dateOfBirth [year] = 1911 // & hobbies [0] = coding & hobbies [1] = eating & hobbies [2] = sleeping & hobbies [3] [0] = nested & hobbies [3] [1] = stuff copy code into response ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------Ext. Number constrain (Number number Number, Number min, Number max): Number checks whether the given value is within the range of the constraint. If it is within the range, this value is returned. Otherwise, if the value is greater than the maximum value, the maximum value is returned. If the value is smaller than the minimum value, the minimum value is returned. Note that this method does not change the given value itself randomInt (Number from, Number ): number returns a random Number toFixed (Number value, Number precision) decimal choice alert (Ext. number. toFixed (3.1415926, 5); // The result is 3.142 bytes distributed Ext. string capitalize (String string): String returns the trim (String string String) in upper case of the first letter. For details, refer to "String" var s = 'foo bar '; alert ('-' + s + '-'); // alerts "-foo bar-" alert ('-' + Ext. string. trim (s) + '-'); // alerts "-foo bar -"