Created
June 20, 2013 03:51
-
-
Save ghempton/5820190 to your computer and use it in GitHub Desktop.
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
// 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