Ext.Object

Files

A collection of useful static methods to deal with objects.

Defined By

Properties

Ext.Object
view source
: Objectprivate
Defined By

Methods

Ext.Object
view source
( object )
Returns a new object with the given object as the prototype chain. ...

Returns a new object with the given object as the prototype chain.

Parameters

  • object : Object

    The prototype chain for the new object.

Ext.Object
view source
( object )private
...

Parameters

Ext.Object
view source
( object, fn, [scope] )
Iterate through an object and invoke the given callback function for each iteration. ...

Iterate through an object and invoke the given callback function for each iteration. The iteration can be stop by returning false in the callback function. This method iterates over properties within the current object, not properties from its prototype. To iterate over a prototype, iterate over obj.proto instead of obj. In the next example, use Ext.Object.each(Person.proto ....) and so on. For example:

var person = {
    name: 'Jacky',
    hairColor: 'black',
    loves: ['food', 'sleeping', 'wife']
};

Ext.Object.each(person, function(key, value, myself) {
    console.log(key + ":" + value);

    if (key === 'hairColor') {
        return false; // stop the iteration
    }
});

Parameters

  • object : Object

    The object to iterate

  • fn : Function

    The callback function.

    Parameters

    • key : String
    • value : Mixed
    • object : Object

      The object itself

  • scope : Object (optional)

    The execution scope (this) of the callback function

Ext.Object
view source
( queryString, [recursive] ) : Object
Converts a query string back into an object. ...

Converts a query string back into an object.

Non-recursive:

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%20price=%24300"); // returns {'some price': '$300'}
Ext.Object.fromQueryString("colors=red&colors=green&colors=blue"); // returns {colors: ['red', 'green', 'blue']}

Recursive:

Ext.Object.fromQueryString("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", true);

// returns
{
    username: 'Jacky',
    dateOfBirth: {
        day: '1',
        month: '2',
        year: '1911'
    },
    hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
}

Parameters

  • queryString : String

    The query string to decode.

  • recursive : Boolean (optional)

    Whether or not to recursively decode the string. This format is supported by PHP / Ruby on Rails servers and similar.

    Defaults to: false

Returns

Ext.Object
view source
( object, value )
Returns the first matching key corresponding to the given value. ...

Returns the first matching key corresponding to the given value. If no matching value is found, null is returned.

var person = {
    name: 'Jacky',
    loves: 'food'
};

alert(Ext.Object.getKey(sencha, 'food')); // alerts 'loves'

Parameters

Ext.Object
view source
( object ) : String[]
Gets all keys of the given object as an array. ...

Gets all keys of the given object as an array.

var values = Ext.Object.getKeys({
    name: 'Jacky',
    loves: 'food'
}); // ['name', 'loves']

Parameters

Returns

  • String[]

    An array of keys from the object.

Ext.Object
view source
( object ) : Number
Gets the total number of this object's own properties. ...

Gets the total number of this object's own properties.

var size = Ext.Object.getSize({
    name: 'Jacky',
    loves: 'food'
}); // size equals 2

Parameters

Returns

Ext.Object
view source
( object ) : Array
Gets all values of the given object as an array. ...

Gets all values of the given object as an array.

var values = Ext.Object.getValues({
    name: 'Jacky',
    loves: 'food'
}); // ['Jacky', 'food']

Parameters

Returns

  • Array

    An array of values from the object.

Ext.Object
view source
( source, objs ) : Object
Merges any number of objects recursively without referencing them or their children. ...

Merges any number of objects recursively without referencing them or their children.

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

// sencha then equals 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
    }
}

Parameters

  • source : Object

    The first object into which to merge the others.

  • objs : Object...

    One or more objects to be merged into the first.

Returns

  • Object

    The object that is created as a result of merging all the objects passed in.

Ext.Object
view source
( source )
...

Parameters

Ext.Object
view source
( name, value, [recursive] ) : Object[]
Convert a name - value pair to an array of objects with support for nested structures; useful to construct query stri...

Convert a name - value pair to an array of objects with support for nested structures; useful to construct query strings. For example:

Non-recursive:

var objects = Ext.Object.toQueryObjects('hobbies', ['reading', 'cooking', 'swimming']);

// objects then equals:
[
    { name: 'hobbies', value: 'reading' },
    { name: 'hobbies', value: 'cooking' },
    { name: 'hobbies', value: 'swimming' }
]

Recursive:

var objects = Ext.Object.toQueryObjects('dateOfBirth', {
    day: 3,
    month: 8,
    year: 1987,
    extra: {
        hour: 4,
        minute: 30
    }
}, true);

// objects then equals:
[
    { 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 }
]

Parameters

  • name : String
  • value : Object
  • recursive : Boolean (optional)

    true to recursively encode any sub-objects.

    Defaults to: false

Returns

  • Object[]

    Array of objects with name and value fields.

Ext.Object
view source
( object, [recursive] ) : String
Takes an object and converts it to an encoded query string. ...

Takes an object and converts it to an encoded query string.

Non-recursive:

Ext.Object.toQueryString({foo: 1, bar: 2}); // returns "foo=1&bar=2"
Ext.Object.toQueryString({foo: null, bar: 2}); // returns "foo=&bar=2"
Ext.Object.toQueryString({'some price': '$300'}); // returns "some%20price=%24300"
Ext.Object.toQueryString({date: new Date(2011, 0, 1)}); // returns "date=%222011-01-01T00%3A00%3A00%22"
Ext.Object.toQueryString({colors: ['red', 'green', 'blue']}); // returns "colors=red&colors=green&colors=blue"

Recursive:

Ext.Object.toQueryString({
    username: 'Jacky',
    dateOfBirth: {
        day: 1,
        month: 2,
        year: 1911
    },
    hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
}, true);

// returns the following string (broken down and url-decoded for ease of reading purpose):
// 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

Parameters

  • object : Object

    The object to encode.

  • recursive : Boolean (optional)

    Whether or not to interpret the object in recursive format. (PHP / Ruby on Rails servers and similar).

    Defaults to: false

Returns