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, value} from "can";
const outer = new DefineMap({
inner: {
key: "hello"
}
});
const keyObservable = value.bind(outer, "inner.key");
// reading `keyObservable.value`, we get the value at `outer.inner.key`
console.log( keyObservable.value ); //-> "hello"
// writing to `keyObservable.value` will change the value at `outer.inner.key`
keyObservable.value = "aloha";
console.log( 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.