Given:
class Base
class User extends Base
@name: true
Coffeescript generates a constructor for you like this:
Base = (function() {
function Base() {}
return Base;
})();
User = (function(_super) {
__extends(User, _super);
function User() {
User.__super__.constructor.apply(this, arguments);
}
User.name = true;
return User;
})(Base);
In order to make this use Ember.js, you have to change both the __extends
and that function User
call, to look like this:
User = (function(_super) {
var User;
if (_super.isEmberObject)
User = _super.extend();
else {
User = function() {
User.__super__.constructor.apply(this, arguments);
}
}
User.name = true;
return User;
})(Base);
But then still, that won't work… You need to apply the class/instance methods the same way ember does:
User = (function(_super) {
var User;
if (_super.isEmberObject) {
User = _super.extend();
User.reopenClass({
name: true
});
} else {
User = function() {
User.__super__.constructor.apply(this, arguments);
}
User.name = true;
}
return User;
})(Base);
I tried doing _.extend(User, _super.extend())
, but that doesn't apply the instance/class methods properly. There's no way to make the constructor function work differently from the outside either…
Hmm… Looks like ember would have to change their architecture to make this work anyway.