require.config({baseUrl: "http://ibm-js.github.io/libraries/master/"}); require(["deliteful-build/layer"], function () { require(["decor/Observable"], function (Observable) { function Point(x, y) { Observable.assign(this, {x: x, y: y}); this.move = function (distance, angle) { Observable.getNotifier(this).performChange("move", function () { this.set("x", this.x + distance * Math.cos(angle)); this.set("y", this.y + distance * Math.sin(angle)); return { distance: distance, angle: angle }; }.bind(this)); }; } Point.prototype = Object.create(Observable.prototype); Point.observe = function (point, callback) { return Observable.observe(point, callback, ["add", "update", "delete", "move"]); }; var point = new Point(0, 0); Observable.observe(point, function (records) { document.getElementsByTagName("pre")[0].innerHTML = "Observable.observe():\n" + JSON.stringify(records, null, 4); }); Point.observe(point, function (records) { document.getElementsByTagName("pre")[1].innerHTML = "Point.observe():\n" + JSON.stringify(records, null, 4); }); window.change = function () { point.move(1, Math.PI / 4); }; }); });