Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove util/extend and use prototypal inheritance #119

Open
zship opened this issue Jun 25, 2014 · 1 comment
Open

Remove util/extend and use prototypal inheritance #119

zship opened this issue Jun 25, 2014 · 1 comment
Milestone

Comments

@zship
Copy link
Contributor

zship commented Jun 25, 2014

This is a big one because this is Lavaca's classical inheritance mechanism. My argument for removing it would be to reduce complexity by removing one level of abstraction. It also hides dependencies because classes do not directly depend on it (it adds a method called extend to passed constructors). We only use single inheritance, so Javascript's own prototypal inheritance via Object.create() would accomplish the exact same thing in the same number of lines.

It implicitly touches everything we call a "class", through the .extend() method it adds to the passed constructor function. Directly it only touches util/Promise and util/Disposable.

@zship zship added this to the 3.0 milestone Jul 1, 2014
@zship zship removed the enhancement label Jul 21, 2014
@zship zship removed the v3 label Jul 31, 2014
@zship
Copy link
Contributor Author

zship commented Jul 31, 2014

Bummer. I just noticed that we use the this.constructor property once in mvc/Model:325. That makes vanilla prototypal inheritance more boilerplate-y... example:

var TestModel = function() {
  Model.apply(this, arguments);
};
TestModel.prototype = Object.create(Model.prototype);
TestModel.prototype.constructor = TestModel;
mixin(TestModel.prototype, {
  idAttribute : 'myId'
});

// vs how it is currently:

var TestModel = Model.extend({
  idAttribute : 'myId'
});

We can put this on the back-burner. Maybe use es6 classes through traceur? If nothing else, I think it might be nice to modify util/extend to not add a .extend() method to every class so that scripts must require it to use it (avoid hiding dependencies, that is)... might make a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant