How can I pass arguments to init()
or access the arguments passed to create()
inside init()
in ember.js
Use closures and create a new init function that passes the closed argument to its prototype init function. Also, this way you don't end up overwriting sensitive properties, like methods for example. note: init is called after all the properties are set by the constructor
Class = Ember.Object.extend({
init:function(response){
console.log(this.get("msg")+this.get("msg_addressee")+"?");
console.log(response);
},
msg:"SUP, "
});
var arg = "not much.";
obj = Class.create({
init:function(){
console.log("output:");
this._super(arg);
console.log("indeed, "+arg);
},
msg_addressee:"dude"
});
//output:
//SUP, dude?
//not much.
//indeed, not much.