dojo.getObject

Status:Draft
Version:1.0
Available:since V?

dojo.getObject returns the property of an object from a dot-separated string such as “A.B.C”

Usage

The simplest way to use dojo.getObject is to pass a dot-separated string as shown below:

1
2
3
4
5
6
7
8
9
<script type="text/javascript">
  // define an object
  var foo = {
    bar: "some value"
  };

  // get the "foo.bar" property
  dojo.getObject("foo.bar");  // returns "some value"
</script>

dojo.getObject also takes an optional boolean parameter which, if true, will create the property if it does not exist. Any other properties along the path will also be created along the way. The default value is false.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<script type="text/javascript">
  // define an object
  var foo = {
    bar: "some value"
  };

  // get the "foo.baz" property, create it if it doesn't exist
  dojo.getObject("foo.baz", true); // returns foo.baz - an empty object {}
  /*
    foo == {
      bar: "some value",
      baz: {}
    }
  */
</script>

You can also pass an object as the third parameter. This will define the context in which to search for the property. By default, the context is dojo.global.

1
2
3
4
5
6
7
8
9
<script type="text/javascript">
  // define an object
  var foo = {
    bar: "some value"
  };

  // get the "bar" property of the foo object
  dojo.getObject("bar", false, foo); // returns "some value"
</script>

Table of Contents

Error in the documentation? Can’t find what you are looking for? Let us know!