Skip to content

Instantly share code, notes, and snippets.

@prettycode
Created April 10, 2016 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prettycode/273a13efba58b928df297ae45d553632 to your computer and use it in GitHub Desktop.
Save prettycode/273a13efba58b928df297ae45d553632 to your computer and use it in GitHub Desktop.
Evaluate functions on object
Model.prototype.$extended = function () {
var thisModel = this,
extendedModel = angular.copy(thisModel);
Object
.keys(thisModel)
.filter(key => typeof thisModel[key] === 'function')
.forEach(key => {
try {
extendedModel[key] = thisModel[key]();
}
catch (err) {
// expected. some methods require arguments, so swallow.
}
})
;
return extendedModel;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment