Created
April 10, 2016 03:07
-
-
Save prettycode/273a13efba58b928df297ae45d553632 to your computer and use it in GitHub Desktop.
Evaluate functions on object
This file contains hidden or 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
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