This is possible if you would change they way you load classes. if you were
to do:
var a = Loader.load('Fx.Morph',args);
//or even better:
var a = Class.init('Fx.Morph',args); //bad naming i think but it should go
with class
instead of
var a = new Fx.Morph;
Then the skies are the limit. but this is simply not the way you load
classes with Mootools. There is no reason not to do so. it would als be much
_much_ simpler to implement:
http://jsfiddle.net/ubSaS/
this can also be coupled with any type of more sophisticated loading method
(such as my Loader class);
-----------
אריה גלזר
052-5348-561
5561
On Tue, Apr 20, 2010 at 15:53, batman42ca <[email protected]> wrote:
> I'm not asking to have the "new" operator overloaded. I'm asking if
> it's possible for your Loader class to know the name of the class it's
> about to instantiate. My guess is that Javascript provides no way to
> automatically determine the class name. I would probably have to
> explicitly pass the javascript file name to your loader.
>
> With the __autoload function working in a way simiar to the PHP model,
> if class A depends on both class B and C, intantiating class A causes
> __autoload() to be called with the name of class A and it loads
> "a.js", then when the object for A tries to instantiate class B, the
> act of instantiation triggers the same mechanism and instantiating
> class B causes "b.js" to be loaded by __autoloader().
>
> That way, I never have to care that A depends on B or C because it
> doesn't. A depends on "a.js", B depends on "b.js", C depends on
> "c.js". As long as the javascript files are present on the server,
> there is only ever a single level of dependency. Each class is only
> dependent upon it's own source file. That is how the __autoload() in
> PHP works.
>
> As near as I can tell, your loader class or a derivation of it, is one
> step away from achieving that. Get the name of the class being
> instantiated to your __autoload() function and you've got a javascript
> equivalent of PHP's __autoload() function provided __autoload() can
> load the javascript file synchronously..
>
> On Apr 20, 3:47 am, אריה גלזר <[email protected]> wrote:
> > > My original intent was to find a way to cause the instantiation of a
> > > class to pass the name of that class to an __autoload function so that
> > > the __autoload function could load the javascript that contains that
> > > class. So __autoload() needs to be passed the name of the instantiated
> > > class.
> >
> > As many people already said - that is simply not possible with JS. you
> > cannot override the new operator, and you cannot add behavior to it.
> > You simply cannot use an object's identifier (whether with new, passing a
> > reference or calling it as a function) without loading it first.
> >
> > all you can do is try to fake it with the dependencies...
> >
> > --
> > Subscription settings:
> http://groups.google.com/group/mootools-users/subscribe?hl=en
>