Skip to content

Instantly share code, notes, and snippets.

@ghempton
Created June 20, 2013 03:51
Show Gist options
  • Save ghempton/5820190 to your computer and use it in GitHub Desktop.
Save ghempton/5820190 to your computer and use it in GitHub Desktop.
// dynamically creating classes + computed properties
// result of ajax request, these are the fields and their dependencies
var fields = {'name': {'firstName', 'lastName'}};
var mixin = {};
for(var name in fields) {
var field = fields[name];
mixin[name] = function() {
return this.get(fields[0]) + ' ' + this.get(fields[2]);
}.property(fields[0], fields[1]);
}
var DynamicController = Ember.Controller.extend(mixin);
var controller = DynamicController.create({
firstName: 'herp',
lastName: 'derp'
});
console.log(controller.get('name')); // returns 'herp derp'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment