jQuery getObject: get.and.set.deep.objects.easily = true;

Version: 1.1, Last updated: 12/24/2009

Project Homehttp://benalman.com/projects/jquery-getobject-plugin/
GitHubhttp://github.com/cowboy/jquery-getobject/
Sourcehttp://github.com/cowboy/jquery-getobject/raw/master/jquery.ba-getobject.js
(Minified)http://github.com/cowboy/jquery-getobject/raw/master/jquery.ba-getobject.min.js (0.7kb)
Summary
jQuery getObject: get.and.set.deep.objects.easily = true;Version: 1.1, Last updated: 12/24/2009
LicenseCopyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.
Support and TestingInformation about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).
Release History
Note for non-jQuery usersjQuery isn’t actually required for this plugin, because nothing internal uses any jQuery methods or properties.
Note for Dojo usersThe setObject, getObject, and exists methods are similar to their Dojo counterparts, with the exception that exists returns true or false based on whether or not a property is defined, not whether it is truthy.
Functions
jQuery.getObjectGet a property of an object via dot-delimited name string, and optionally create the property and any ancestor properties that do not already exist.
jQuery.setObjectSet a property of an object via dot-delimited name string, creating any ancestor properties that do not already exist.
jQuery.existsUsing dot-delimited name string, return whether a property of an object exists.

License

Copyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.  http://benalman.com/about/license/

Inspired by Dojo, which is Copyright © 2005-2009, The Dojo Foundation.

Support and Testing

Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).

jQuery Versionsnone, 1.3.2, 1.4a2
Browsers TestedInternet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.
Unit Testshttp://benalman.com/code/projects/jquery-getobject/unit/

Release History

1.1(12/24/2009) Removed dependency on jQuery.  Now creates methods in a `Cowboy` namespace if jQuery isn’t present.
1.0(12/19/2009) Initial release

Note for non-jQuery users

jQuery isn’t actually required for this plugin, because nothing internal uses any jQuery methods or properties. jQuery is just used as a namespace under which these methods can exist.

Since jQuery isn’t actually required for this plugin, if jQuery doesn’t exist when this plugin is loaded, the methods described below will be created in the `Cowboy` namespace.  Usage will be exactly the same, but instead of $.method() or jQuery.method(), you’ll need to use Cowboy.method().

Note for Dojo users

The setObject, getObject, and exists methods are similar to their Dojo counterparts, with the exception that exists returns true or false based on whether or not a property is defined, not whether it is truthy.

Functions

jQuery.getObject

Get a property of an object via dot-delimited name string, and optionally create the property and any ancestor properties that do not already exist.

Usage

jQuery.getObject( name [, create ] [, context ] );

Arguments

name(String) Dot-delimited string representing a property name, for example: ‘document’, ‘location.href’, ‘window.open’ or ‘foo.bar.baz’.
create(Boolean) Create final and intermediate properties if they don’t exist.  Defaults to false.
context(Object) Optional context in which to evaluate name.  Defaults to window if omitted.

Returns

(Object) An object reference or value on success, otherwise undefined.

jQuery.setObject

Set a property of an object via dot-delimited name string, creating any ancestor properties that do not already exist.

Usage

jQuery.setObject( name, value, [ context ] );

Arguments

name(String) Dot-delimited string representing a property name, for example: ‘document’, ‘location.href’, ‘window.open’ or ‘foo.bar.baz’.
value(Anything) Any valid JavaScript expression.
context(Object) Optional context in which to evaluate name.  Defaults to window if omitted.

Returns

(Anything) The value if set successfully, otherwise undefined.

jQuery.exists

Using dot-delimited name string, return whether a property of an object exists.

Usage

jQuery.exists( name [, context ] );

Arguments

name(String) Dot-delimited string representing a property name, for example: ‘document’, ‘location.href’, ‘window.open’ or ‘foo.bar.baz’.
context(Object) Optional context in which to evaluate name.  Defaults to window if omitted.

Returns

(Boolean) Whether or not the property exists.

Close