Re: "with" statement, extending prototype
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: "with" statement, extending prototype

From: <eman1000@gmail.com>
Date: Wed Apr 05 2006 - 16:00:19 CEST

First I want to thank you for your feedback. I am one of the waves of
programmers who misunderstood Javascript for many years until the
recent development of Ajax libraries (such as prototype) have showed me
just how cool Javascript can be. I'm still trying to understand all the
details so I greatly appreciate any corrections to my understanding.

RobG wrote:
> > which is the exact same as:
> >
> > <current scope object>.myfunc = function() {}
>
> Where 'current scope object' is what, an object? It is equivalent to
> assigning an anonymous function to the myfunc property of the object.

<current scope object> referred to the last item added to the scope
chain. I thought identifiers created in the current scope were really
properties of the last item added to the scope chain. Maybe this is my
misunderstanding.

> > Of course most of the time you can't access the top item on the scope
> > chain
>
> Isn't the 'top item' always the global object? Or do you mean 'this'?

By "top item" I meant the last item added to the scope chain (I am
thinking about it like a stack with objects being popped on and off the
scope chain as you enter and exit functions).

> No errors because it 'works'. The function does get added, but as a
> private member, not public - Mike Winter or someone can likely explain
> how that works, not me!.

Hmmm.... I'm not sure I understand this private vs public member stuff.
Will have to do some reading on it. Thanks for pointing me in the right
direction.

> To use 'with' and keep start() public, you can use:
>
> with (Car){
> prototype.start = function(){alert('starting');};
> }
>

I'm not sure I understand why:

with (Car) {
    prototype.start = function() {alert('starting');};
}

isn't equivilant to:

with (Car.prototype) {
    start = function() {alert('starting');};
}

Once again thanks for your feedback,

Eric
Received on Mon May 1 04:42:51 2006