If you had the external file "foo.js" and inside "foo.js" was a class called
"bar", you want, the command "new bar()" to load "foo.js" in a script tag
and initiate the class "bar", is this right?

Well, the only way that I know of that you could accomplish such a thing in
pure JS is to intercept the call to "new" determine what file the class
desired is located in. But, short of joining the Mozilla dev team and
writing that in to the next version of JavaScript I would venture to say you
are out of luck. As far as I know, there is no hook or event that gets
triggered when you issue the command "new".  

However, thinking out loud a minute you might be able to trap for an error
then use a async ajax query that calls a php function that scans a directory
of files for the class you want.  Returns the file name and dynamically
loads it, then tries to create the class.  (takes a deep breath, then falls
over from exhaustion)


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Sanford Whiteman
Sent: Tuesday, April 06, 2010 10:48 PM
To: batman42ca
Subject: Re: [Moo] Re: __autoload()

> I'm trying to avoid needing to provide a list of classes. I trying to
> get the act of instantiating a class to trigger the loading of the
> javascript for that class if the class isn't already defined.That way,
> the dependencies automatically take care of themselves.

You, um, want to overload operator new in JS?

I  can't see any reason for that to be possible -- maybe in some freak
old  browser  or  something  (or  obvs.  if  you  build  your  own  JS
interpreter).  I  think  even  in the failed overloading proposals for
ES4, new wasn't included.

-- Sandy






-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to