Created
August 11, 2017 05:27
-
-
Save Gomah/8ac0325fe67894a3b8e238094dcba7bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class GraphModel { | |
/** | |
* @param {Object} attrs Attributes on the GraphModel. | |
*/ | |
constructor(attrs) { | |
Object.defineProperty(this, 'attrs', { value: attrs, enumerable: false }); | |
Object.keys(this.attrs).filter(key => !(key in this)).forEach(key => { | |
let descriptor; | |
if (attrs[key] === null) { | |
descriptor = { | |
enumerable: true, | |
get() { | |
return null; | |
}, | |
}; | |
} else { | |
descriptor = { | |
enumerable: true, | |
get() { | |
return this.attrs[key].valueOf(); | |
}, | |
}; | |
} | |
Object.defineProperty(this, key, descriptor); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment