From: Scott A. L. <sc...@sc...> - 2000-10-31 17:02:37
|
I think what's being overlooked in your idea is that prototype methods won't be inherited. makeWidget creates a string of the contents of the *constructor*; but it doesn't include the prototype properties. It looks like makeWidget creates an entire new constructor. If you passed DynLayer to makeWidget it would return a completely new object identical to DynLayer constructor as your widget base, plus any modifications you made. Is this a good approach? scottandrew Jordi 'IlMaestro' Ministral wrote: > > What is trying to do is, given that the toString method of a function return its > source code, is to add lines just after "function() {" and before the source, and then > eval the new function. So the function passed as parameter is rewriten. > > This way we can have clean widget constructors and automatically add all the > initializations code that make a widget a widget. If this code is to be changed we > don't have to bother editing th widget sources because that inheriting code is added > by the API and not hard-coded into each constructor. > > The idea is turn method to string, split into to strings: until { and after }, insert > our code between them and eval everything. > > Robert Rainwater wrote: > > > I'm not quite sure I follow your DynAPI.makeWidget. Could you explain > > that in a little more detail. I don't understand what makeWidget is > > trying to do there. > > > > Robert > > > > -- > > Email: <mailto:rra...@ya...> > > PGP Key ID: 0x703D7F7C > > > > > I've been thinking about this for some tome now and our main problem here is > > > having all our widgets to share the DynLayer functionalities without sharing any > > > properties. We need some sort of initialization code such as: > > > > > > myWidget = function() { > > > // Init code > > > > > > // Assign id > > > this.id = ... > > > > > > // Widget stuff starts here > > > > > > } > > > > > > // Maybe not anymore > > > myWidget.prototype > > > > > > > > > However hard-coding it into all our widgets is a pain and when we need to change > > > something then we have to edit all of your widgets and we force people to > > > 'remember' whet has to be placed at the beggining of each constructor. I thing > > > this can be solved by having this method (this is the idea, I haven't been able > > > to code it) > > > > > > DynAPI.makeWidget = function(constructor) { > > > var code = window[constructor].toString() > > > // now we have the code > > > var header = code.substring(0,code.indexOf("{")) > > > var rest = code.substring(code.indexOf("{")) > > > var newcode = header + have all the common init stuff in a String here + rest > > > eval(constructor+" = "+newcode) > > > > > > // If needed attach prototying, assign variables, etc. > > > } > > > > > > > > > This way your widget code should be independent of the inheritance method > > > adopted. This I presume, I haven't tested. Tell me what you think > > > > > > > _______________________________________________ > > Dynapi-Dev mailing list > > Dyn...@li... > > http://lists.sourceforge.net/mailman/listinfo/dynapi-dev > > _______________________________________________ > Dynapi-Dev mailing list > Dyn...@li... > http://lists.sourceforge.net/mailman/listinfo/dynapi-dev |