Search code examples
javascriptobjectember.jsobjectinstantiation

Ember.js stringtoclass


I'm searching a way to instatiate a new ember object with the classname as a string:

App.MyObject = Ember.Object.extend({hello:'hello'});
//Try to do something like this.
App.myObject = Ember.create("App.MyObject", {hello:'Hello World!'});
console.log(App.myObject.hello); //productes 'Hello World!'

Is there a possibility to do something like this?


Solution

  • I think you dont need to use getters and setters in your special case.

    Your solution was

    Ember.get(window, "App.MyObject").create({hello:'Hello World!'});
    

    But I think a simple one like:

    var className = "MyObject";
    App[className].create({hello:'Hello World!'});
    

    will work.