A constructor for objects with attribute accessors that emit
read events upon setting or getting an attribute. Fully compatible with CommonJS (Node), AMD and standard browser script tag include.
wheels-loud-accessors can be included in a project with CommonJS / npm, AMD or standard browser script tag. Its dependencies are
npm install wheels-loud-accessors
AMD / RequireJS
// Remember to provide the dependencies `wheels-pubsub` and `wheels-class`;
Traditional browser script tag
LoudAccessors is a class (created with
wheels-class) inheriting from
wheels-pubsub and introducing
set instance methods, as well as an
attrAccessors class method.
var foo = ;foo;foo; // console: Attribute bar was set to value 123foo; // 'silently' set attribute, no event triggered
var foo = ;foo;foo; // console: Attribute bar was readfoo; // 'silently' get attribute, no event triggered
Object.defineProperty, we can even do without
var Foo = LoudAccessorsfoo = ;foo;foo;foobar = 123; // console: Attribute bar was set to value 123var qux = foobar; // console: Attribute bar was read