bind
Get an observable for getting and setting a property on an object.
value.bind( object, keyPath )
In the example below, a keyObservable
is created that is two-way bound to the
value at outer.inner.key
. When keyObservable.value
changes,
outer.inner.key
is updated, and vice versa.
import DefineMap from "can-define/map/map";
import value from "can-value";
const outer = new DefineMap({
inner: {
key: "hello"
}
});
const keyObservable = value.bind(outer, "inner.key");
// keyObservable.value === "hello"
keyObservable.value = "aloha";
// outer.inner.key === "aloha"
Parameters
- object
{Object}
:The object from which to read.
- keyPath
{String}
:A String of dot-separated keys, representing a path of properties.