Skip to content

Instantly share code, notes, and snippets.

@thephw
Last active December 15, 2015 20:58
Show Gist options
  • Save thephw/5321913 to your computer and use it in GitHub Desktop.
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.
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