Last active
December 15, 2015 20:58
-
-
Save thephw/5321913 to your computer and use it in GitHub Desktop.
Why people should hate me... dynamic method generation in a static configuration file. Whatever, whatever, I do what I want.
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
exports.definition = { | |
config: { | |
extra_methods: [ | |
{ | |
name: 'test', | |
url: 'test', | |
type: 'get' | |
} | |
], | |
extendModel: function(Model) { | |
if(Model.config.extra_methods) { | |
_.each(Model.config.extra_methods, function(extra_method) { | |
var extensions = (new Function('return {'+ extra_method.name +': function(options){this.sync("' + extra_method.name + '", this, options);}}'))(); | |
_.extend(Model.prototype, extensions); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment