Is there such a thing as this.value ?

L

Lasse Reichstein Nielsen

Evertjan. said:
Lasse Reichstein Nielsen wrote on 26 jun 2011 in comp.lang.javascript:
Evertjan. said:
Stanimir Stamenkov wrote on 26 jun 2011 in comp.lang.javascript:

26 Jun 2011 08:10:04 GMT, /Evertjan./:

The scope difference of passing by reference or by value when used
diligently, can save far more time and code lines than the simplistic
implementation referred to here.

As far as I'm aware, in JS one always passes values - either
references to objects, or primitive values. With pass-by-reference
I understand:

No, your understanding is wrong.

No, it is correct.
Variables are passed by value,
[meaning that only the value is passed]
objects are passed by reference,
[meaning thet the object-pointer is passed.]

That's not what "pass by reference" means (in the sense used in
computer science, which was where the terminology was invented). In
pass-py-reference, you pass a reference to a *variable*, not to a
*value*.

As I showed above. You are not adding anything.

No. What you showed was *not* passing a variable. It was passing
a reference to a shared mutable data structure (an object).
As I showed above. You are not adding anything.

You are missing the point.
That you ALSO can call it by another name is fine.

That's not a different name for the same thing. It's a different
name for a DIFFERENT thing.
I think your argumentation is therefore utter nonsense.

I will expand my above reasoning:

Function arguments containing a variable

How can an argument "contain" a variable?
Inside the function, the argument is available *as* a variable
(the formal parameter of the function).
Outside, it's just a value.
only pass IT'S CONTAINING VALUE

What is a "containing value"? Which value is it and what does it
contain?
and NOT THE REFEREBENCE TO THE VARIABLE.

Are you saying that calling the function with a variable expression as
an argument, the value passed as the argument to the call is the value
bound to the variable, and not a reference to the variable itself?
In that case, yeS:
So the argument name is a new variable with local scope.
This is called "passing by value".

This is exactly passing by value.

While function arguments containing an object
pass the REFERENCE TO THAT OBJECT,
and NOT IT'S CONTENTS.

If you write
foo(o)
and o is a variable bound to an object, then o really holds
a reference to the object, not the object itself.
That's why you can make assignments without breaking identity:
var o1 = {x:42};
var o2 = o1;
o2.x = 37;
alert(o1.x); // 37.
So the argument name is just another name of the object
where only the name has local scope.

No, argument name (aka. formal parameter name) defines a local
variable holding the same value as the one passed in.

So if you have:
function foo(x) { x.y = 42; x = 10;}
var o = {y:37};
foo(o);
alert(o.y);
then you pass the value of o, the reference to the object, into
foo. Then foo's x and the surrounding scope's o variables have the same
*value*. However, they are not the *same variable*. That is why doing
x = 10;
does not make o have the value 10.
If it had been pass-by-reference, then o would have had the value 10.
This is called "passing by reference".

No, it's not. Passing by reference makes the argument variable and
*alias* of the passed in variable. Changing one will change the other.
That does not happen here.

It's pass by sharing, which is different from pass by reference, as
explained in, e.g., the wikipedia article.
Javascript/ECMAScript only have pass-by-sharing. It doesn't have
pass-by reference.

C++ has pass-by-reference. Example:

#include <iostream>
using namespace std;

class A {
public:
int x;
}

void by_reference(A& x) { x.x = 10; }
void by_value(A x) { x.x = 10; }

int main(int argc, char* argv[]) {
A o = { 42 }; // o is a variable holding an object.
cout << o.x << endl; // prints 42
by_value(o); // Passing the value of o by value.
cout << o.x << endl; // prints 42
by_reference(o); // Passing o by reference.
cout << o.x << endl; // prints 10
return 0;
}

You can't do that in Javascript.

/L
 
E

Evertjan.

Lasse Reichstein Nielsen wrote on 26 jun 2011 in comp.lang.javascript:
Evertjan. said:
Lasse Reichstein Nielsen wrote on 26 jun 2011 in comp.lang.javascript:
Stanimir Stamenkov wrote on 26 jun 2011 in comp.lang.javascript:

26 Jun 2011 08:10:04 GMT, /Evertjan./:

The scope difference of passing by reference or by value when used
diligently, can save far more time and code lines than the simplistic
implementation referred to here.

As far as I'm aware, in JS one always passes values - either
references to objects, or primitive values. With pass-by-reference
I understand:

No, your understanding is wrong.

No, it is correct.

Variables are passed by value,
[meaning that only the value is passed]
objects are passed by reference,
[meaning thet the object-pointer is passed.]

That's not what "pass by reference" means (in the sense used in
computer science, which was where the terminology was invented). In
pass-py-reference, you pass a reference to a *variable*, not to a
*value*.

As I showed above. You are not adding anything.

No. What you showed was *not* passing a variable. It was passing
a reference to a shared mutable data structure (an object).

I never said you could pass a variable.

You can pass a value, as contained in a variable,
and you can pass the access to an object.

"a shared mutable data structure"?
Don't be daft, let's jus keep calling that an object.

You are missing the point.

NO !

Perhaps I am missing your point,
but your point isn'r neccessarily THE point.


That's not a different name for the same thing. It's a different
name for a DIFFERENT thing.

So why do you say "also known as"?
How can an argument "contain" a variable?

Because an argument-position of a function can be filled with a variable,
of wich only the containing value is passed to the function.

The word function meaning two things:
1 the function with arguments in the calling position
2 the function declaration.

This is only important if you want to be difficult.
Inside the function, the argument is available *as* a variable
(the formal parameter of the function).
Outside, it's just a value.

Indeed, this proves you want to be difficult.
What is a "containing value"? Which value is it and what does it
contain?

You want to be difficult: a variabe contains a value.

Are you saying that calling the function with a variable expression as
an argument, the value passed as the argument to the call is the value
bound to the variable, and not a reference to the variable itself?
In that case, yeS:


This is exactly passing by value.

So why are you being difficult?

It seems you agree.

If you write
foo(o)
and o is a variable bound to an object, then o really holds
a reference to the object, not the object itself.
That's why you can make assignments without breaking identity:
var o1 = {x:42};
var o2 = o1;
o2.x = 37;
alert(o1.x); // 37.

What the heck is "breaking identity"?

alert(o1.x)

You are passing by value,
because you are not passing an object but a litteral value of an
intrinsic [=unnamed] variable.

No, argument name (aka. formal parameter name) defines a local
variable holding the same value as the one passed in.

So if you have:
function foo(x) { x.y = 42; x = 10;}
var o = {y:37};
foo(o);
alert(o.y);
then you pass the value of o,

No, you are passing the computed result, not the object.
the reference to the object, into
foo. Then foo's x and the surrounding scope's o variables have the same
*value*. However, they are not the *same variable*. That is why doing
x = 10;
does not make o have the value 10.
If it had been pass-by-reference, then o would have had the value 10.

No, because you are not passing an object, but an intrinsic variable
result of a computation.
No, it's not. Passing by reference makes the argument variable and
*alias* of the passed in variable. Changing one will change the other.
That does not happen here.

Being difficult again?

"does not happen here" Does not happen where?
It's pass by sharing, which is different from pass by reference, as
explained in, e.g., the wikipedia article.

Wiki is not proof of anything.

Passing by reference by any other name works just the same, [smelling
like Shakespeare's rose.]
Javascript/ECMAScript only have pass-by-sharing. It doesn't have
pass-by reference.

Repeating yourself does not make it true.

Objects in Javascript function arguments are passed by reference,
not passed by sharing, simply because the whole ideaa of passing by
sharing is nonsense.

You could call the result of passing by reference "use by sharing"
because the same object is used by pointers in differen scopes, but the
sharing is not passed, the reference is.

C++ has pass-by-reference. Example: [...]

You can't do that in Javascript.

I am not interested in C++, or what it cannot do, or how things are
defined there, and that passing by reference is done perhaps differently
there has no incling on what happens in javascript, which is passing by
reference.
 
S

Stanimir Stamenkov

26 Jun 2011 22:23:59 GMT, /Evertjan./:
Lasse Reichstein Nielsen wrote on 26 jun 2011 in comp.lang.javascript:
If you write
foo(o)
and o is a variable bound to an object, then o really holds
a reference to the object, not the object itself.
That's why you can make assignments without breaking identity:
var o1 = {x:42};
var o2 = o1;
o2.x = 37;
alert(o1.x); // 37.

What the heck is "breaking identity"?

alert(o1.x)

You are passing by value,
because you are not passing an object but a litteral value of an
intrinsic [=unnamed] variable.

"Intrinsic [=unnamed] variable" - huh? Objects are allocated in a
heap and variables hold references (their values are references) to
the objects. When there are no more references to an object, it
gets garbage collected.
No, you are passing the computed result, not the object.

"Computed result" - one just passes a reference (by value) which get
dereferenced in the invoked method.

As stated previously "pass-by-reference" means quite different thing
in common programming terminology. You seem to insist on putting
another meaning to it, and I don't think there's much point in
convincing you otherwise, further.
 
L

Lasse Reichstein Nielsen

Evertjan. said:
Objects in Javascript function arguments are passed by reference,
not passed by sharing, simply because the whole ideaa of passing by
sharing is nonsense.

I'll just cut to the bone here.

Objects in Javascript are not passed by reference.
Passing by reference makes an alias of the passed variable - i.e., assigning
to one variable changes the value bound to the other.
That's the definition of passing by reference (aka call by reference), and
means that you can *only* pass a variable that way (an l-value).
Javascript never makes an alias of a variable.

Instead object references are passed by value.
When a variable is passed by value, the parameter variable (local in
the function) holds the same value as the argument variable (the variable
used in argument position), but they are separate, unaliased, variables.
That's the definition of passing by value (aka call by value).

Having simple values passed by value and objects (or other data structures)
that are not passed, but where references to them are passed by value,
is called "call by sharing". You can think it's nonsense, but it never
the less is called that (the term is rather new, it wasn't invented until
1974, needing objects to be invented before).
You could call the result of passing by reference "use by sharing"
because the same object is used by pointers in differen scopes, but the
sharing is not passed, the reference is.

No, the sharing in call-by-reference is at the variable level, not the
value level. That is the difference.
I am not interested in C++, or what it cannot do, or how things are
defined there, and that passing by reference is done perhaps differently
there has no incling on what happens in javascript, which is passing by
reference.

You don't know what passing by reference means, and have no interest in
learning it (you obviouslt did not read the wikipedia page).
You don't know any language that actually can do it, and have no interest
in knowing about it.

Tough.
Bye.
/L
 
J

Jukka K. Korpela

2011-06-27 8:47 said:
Objects in Javascript are not passed by reference.

Well, this (no pun intended) gets somewhat blurry, as people think about
different things and talk in different words. There might be no real
disagreement on matters, on on words. I guess this is what people often
call "semantic talk" (as most people don't know what semantics is).

So to be exact, _objects_ are passed by reference. _Variables_ aren't
(in JavaScript). When you have function call foo(bar) where bar is a
variable, then we can say that the variable bar is passed by value (to
emphasize differences between programming languages), but this _means_
(in the case of an object value) that a reference to an object is
passed, so an object is passed by reference.

Similarly, foo(a+b) causes the expression a+b to be evaluated and the
resulting value passed (by reference, if it as an object). The issue of
"passing an expression", as something different from passing the
computed value of a parameter, does not really arise at all in
JavaScript. But if you wish to emphasize differences between JavaScript
and languages with several parameter passing mechanisms, you can say
that an expression is passed by value - as long as it remains clear that
for an object, this means passing a reference.
 
T

Thomas 'PointedEars' Lahn

Jukka said:
Well, this (no pun intended) gets somewhat blurry, as people think about
different things and talk in different words. There might be no real
disagreement on matters, on on words. I guess this is what people often
call "semantic talk" (as most people don't know what semantics is).

So to be exact, _objects_ are passed by reference. _Variables_ aren't
(in JavaScript).

No! We have been over this ad nauseam, and an MDC article as been fixed
accordingly. The issue is clear enough.

You have no clue about these language*s* (and their applications). Stop
spreading your misconceptions about them as if they were the absolute truth,
sowing further confusion!


PointedEars
 
S

se

Jukka K. Korpela said:
Well, this (no pun intended) gets somewhat blurry, as people think about
different things and talk in different words. There might be no real
disagreement on matters, on on words. I guess this is what people often
call "semantic talk" (as most people don't know what semantics is).

So to be exact, _objects_ are passed by reference. _Variables_ aren't (in
JavaScript). When you have function call foo(bar) where bar is a variable,
then we can say that the variable bar is passed by value (to emphasize
differences between programming languages), but this _means_ (in the case
of an object value) that a reference to an object is passed, so an object
is passed by reference.

Similarly, foo(a+b) causes the expression a+b to be evaluated and the
resulting value passed (by reference, if it as an object). The issue of
"passing an expression", as something different from passing the computed
value of a parameter, does not really arise at all in JavaScript. But if
you wish to emphasize differences between JavaScript and languages with
several parameter passing mechanisms, you can say that an expression is
passed by value - as long as it remains clear that for an object, this
means passing a reference.

What you call a reference of the passed agument
is still a copy. The original from which the copy
is taken gets no altering, what so ever the function
is altering to the copy. The difference "passing by reference/
passing by value" has a universal usage within all programming
language - including javascript.

Taken into consideration your newly accusations and
anger disposed on the alt.html, I may say, I never
before met an aggressive fin. You must be an exception
from the normal fins. Fins drinks a lot (at least used to.
I thinks I would do the same if up there in such a cold region).
I freighted a lot of paper from up there. I never before
met any idjits up there.

You're rather a copy of Adrienne Boswell (perhaps you're a female
having a male navn). Taken the Boswells OT thread into counting,
you seems to dispose a seek wantings of rulling as a self-appointed
moderator, and thinks of yourself as being the only person to know.

Probably a googleing on your name would show up a
whining and punching boy!.
 
J

Jukka K. Korpela

What you call a reference of the passed agument
is still a copy.

I made no such call (no pun intended). Anyway, when an actual parameter
evaluates to an object value, a reference to the object is passed, and
the passed data may be called a copy of the reference (the same
reference may exist e.g. as the value of different variables). But why
would that matter?
The original from which the copy
is taken gets no altering, what so ever the function
is altering to the copy.

Your statements aren't really parseable even with some guesses on what
you might be trying to say.
The difference "passing by reference/
passing by value" has a universal usage within all programming
language - including javascript.

Do you actually know all programming languages? And the difference has
no meaning in languages that have a single parameter passing mechanism,
like JavaScript. Some languages have two or more mechanisms (does anyone
remember "call by name" for example?).

Passing a reference to an object, when passing a parameter (by value),
is just a simple consequence of general definitions. It is quite
comparable to the fact that an assignment a = b operates on the value of
b. If the value of b is of type object, then this value is a reference
to an object.
I never before met an aggressive fin.

It seems that you should not try to catch big fish then.
 
J

Jens Müller

To pass the variable by reference
would mean you can "magically" modify the variable to point to
another object

Which can be achieved (in a rather complicated way) by creating an
accessor object (using closures) that does is.

Of course then it's not done "magically".

- Jens
 
S

se

Stefan Weiss said:
Jukka K. Korpela said:
So to be exact, _objects_ are passed by reference. _Variables_ aren't
(in
JavaScript). When you have function call foo(bar) where bar is a
variable,
then we can say that the variable bar is passed by value (to emphasize
differences between programming languages), but this _means_ (in the
case
of an object value) that a reference to an object is passed, so an
object
is passed by reference.
[..]
What you call a reference of the passed agument
is still a copy. The original from which the copy
is taken gets no altering, what so ever the function
is altering to the copy. The difference "passing by reference/
passing by value" has a universal usage within all programming
language - including javascript.

While I agree with this, on a technical basis, ...
I never before met an aggressive fin. You must be an exception
from the normal fins. [snip insults]

...I wish you'd keep the national stereotyping to yourself.
That position is already filled in cljs.

In the interest of balance, let me present a dissenting stereotypist's
view:
http://satwcomic.com/sauna-time
http://satwcomic.com/a-bad-day
http://satwcomic.com/no-invitation



Oh, and remember Lordi?
http://satwcomic.com/eurovision-winners

You can wish as much as you like, Stefan. You have the rights too.
And I take the rights to answer back in same ways -to anybody -who
treats me an inproper way. No doubt, you know what I'm refereing to.
I did not read your posted urls except the last one. I consider myself
old anough to know what I'm saying and doing. No boys and schoolgirls
(including you) here or any other places should throw a bucket of s**t in
the face of mine without allowing myself to answer back. About your
claiming of national stereotyping as you call my writing, there's not much
other to say than I already said. Any add to it should be: no bad talking of
any nationals in my writings was done. This can clearly be seen in my post.
I just repeat it, as I understand what you're *fishing* after.

About your last posted urls, the one of which I read.:
By posting a content like this, you're yourself are responsible in setting
up
spliting between countries. In fact, you're doing yourself what you really
meant
by your accusement above "accuses another for what you're doing yourself".

You would probably be fully satisfied if/and when the western world become
completely bought up by the chinese.

Keep your own business, Stefan. Don't try to rule the newsgroups as a
self-oppointed moderator or as a better knowing person.

If you ever become an oppointed moderator, Stefan - I'm off then.

/se
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top