-
Notifications
You must be signed in to change notification settings - Fork 639
Multiple class inheritance not working #311
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
Comments
try var A = Class.create({
foo: function() {
alert("A#foo");
}
});
var B = {
bar: function() { alert("B#bar"); }
};
var C = Class.create(A, B, {
baz: function($super) {
alert("C#baz");
}
});
var c = new C();
c.baz();
c.foo();
c.bar(); As first argument pass a superclass ( |
Thanks Fntz, but surely, if I can add a superclass & an object, I should be able to add more than one superclass. Why the restriction? At the moment I have single line ancestry. |
for my opinion multiple inheritance is not always good, but inheritance via traits (or objects in javascript) make sence |
But, it is a hallmark of many classical OO languages. For instance, in your example, I cannot use the $super keyword for methods in the object [argument 2]... |
Use the next trick var A = Class.create({
foo: function() {
alert("A#foo");
}
});
var B = {
bar1: function() { alert("B#bar1"); }
};
A.addMethods(B); // <- extend A class
var C = Class.create(A, {
bar1: function($super) {
alert("C#baz");
$super();
}
});
var c = new C();
c.bar1(); |
So, in terms of building a framework. I could do the following: var modal.package = Class.create({ var layout = { var move = { modal.package.addMethods(layout); var modal = Class.create(modal.package, { So the pattern is, to have one base class package for each related subclass. The base class package consists of a number of mix ins. I can then use a combination of these mix in objects to create new base class packages for different subclasses. |
Yes, of course, a long time ago, i worked on own widgets implementation, where i used a prototype.js. I can see sources in repo |
Wow. Thanks fntz. You have solved my conundrum, in relation to prototype.js & OO. By the way, I really like using prototype.js. More than jQuery... |
you are welcome :) |
I like your widgets. Very clean implementations. I basically use prototype.js classes all the time now & I can now make them even more modular, using this design pattern. I am a little disappointed that the $private keyword patch was not implemented. So I am having to resort to the closure method around the class return... |
You might use the next trick for private methods: var A = function() {
var private_method = function() {
alert("private");
};
var _A = Class.create({
call_private: function() {
private_method();
}
});
return new _A();
};
var a = new A();
a.call_private(); |
Interesting approach, or: |
cool 👍 |
So, further to our discussion this morning, I have come up with the following framework: ---- framework.base.js ----
---- framework.object.callback.js ----
---- framework.object.element.js ----
---- framework.object.events.js ----
---- framework.object.layout.js ----
---- framework.object.move.js ----
---- framework.base.modal.js ----
---- framework.modal.view.js ----
---- framework.modal.notification.js ----
|
Actually, Mike. I am now using ds.oop. It works brilliantly with prototype.js and supports, private, public variables, multiple inheritance, overloading and pretty much everything you would expect from a traditional OO language. I converted the above framework in 5 minutes to ds.oop, which uses almost identical syntax: http://digital-synapse.github.io/ds.oop/ Example: https://github.com/digital-synapse/ds.oop-inheritancetest/blob/master/index.js |
Looks good, by some notes some of the words which used in library are reserved in javascript http://www.javascripter.net/faq/reserved.htm I use a coffeescript but coffee does not have private, protected variables/methods. |
Yes. Mike. The author explains this in a footnote [at the bottom of the page]: https://github.com/digital-synapse/ds.oop/wiki/Getting-Started Apparently, it is easy to change the references to these reserved words... |
var someclassname = Create.class(baseclass1,baseclass2,{
})
This does not inherit both base classes. Multiple inheritance is a cornerstone of any OO framework.
Please could we update this feature to include multiple inheritance.
Thanks
Charlie
The text was updated successfully, but these errors were encountered: