Objects with dynamic attributes

npm install dynobj
4 downloads in the last week
16 downloads in the last month


Dynobj implements a new class of objects that support dynamic get and set functions for dynamic attributes (similar to languages like Python).


var DynObj = new (require('dynobj').DynObj)()
var MyCoolClass = DynObj.create()
MyCoolClass.prototype.__get__ = function(key) {
    return 'cool '+key

MyCoolClass.prototype.__set__ = function(key, val) {
    if (key === 'allowed')
        return true // default behaviour

    // returning anything other that true will suppress the default behaviour and allows you you override
    console.log('someone tried to set '+key)
    return false


As described in LICENSE

npm loves you