Proxy
Where the Proxy object is supported, TKO can wrap objects to make them observable.
>>> const obj = { x: 1,
// Functions are converted to computed properties. x2 () {return this.x * this.x },
// The computed properties are writable, when assigned to rootX (...args) { if (args.length) { this.x = args[0] } return Math.sqrt(this.x) }}>>> const p = ko.proxy(obj)>>> p.x1>>> p.x21>>> p.x = 22// Modifications to the proxy update the original>>> obj.x2>>> p.x24>>> p.rootX = 4
// Add new properties>>> p.y = 6>>> p.x3 = () => this.x * this.x * this.x>>> p.x38
// Create arbitrary dependency chains.>>> const x4 = ko.computed(() => p.x2 * p.x2)>>> x4()16>>> p.x = 0>>> x4()0
// Unwrap the proxy by calling it>>> p() === xtrue// Or assign multiple values>>> p({ x: 9 }){x: 9}