Re: How can I have one function call another function dynamically?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: How can I have one function call another function dynamically?

From: askMe <askMe@askblax.com>
Date: Sun Jul 17 2005 - 14:29:30 CEST

Yann-Erwan Perio wrote:
> Matt Kruse wrote:
>
> Hi,
>
> >>- window[] implies that the host is a browser; using "this" would work
> >>on all browsers, provided the function is called as a member of the
> >>global object,
>
> > Using 'this' is highly sensitive to the calling environment also. For most
> > situations, referencing window[name]() will work while this[name]() might
> > not.
>

I agree. Starting with the window name gives more control over an
object because it forces the programmer to ensure that the 'this'
exists. Least that is what I have always thought.

> As you say, the "this" value depends on the way the function is called:
> if called as a method, then the "this" value will be the reference of
> the object of which it is the method, if called as a function then the
> "this" value will be a reference to the global object.
>
> So if you want a function generic enough to be called as a member of
> different objects (global object, custom object), and only operate with
> the global object for the "this" value, then indeed referencing "window"
> directly would be a good option (while I'd prefer, personally, use a
> construct with an inner function returning the global object).
>
> However I feel that, when calling a function, the "this" value inside
> should be already known and should not depend on how the function is
> called (an external parameter of the function, lack of encapsulation).
>

I agree. But, supposedly, not knowing how the function is called is
better in some situations...

http://www.askblax.com
Received on Tue Oct 18 02:57:12 2005