ECMAScript standard:the code(s) for figure on page 3 ?

O

optimistx

How to write code for an example in the ECMAScript standard?

ECMAScript Standard ECMA-262 , 3rd edition (December 1999) is available as
pdf-file (size 720 951 bytes) to download at
(1)
http://www.ecma-international.org/publications/standards/Ecma-262.htm

and inofficial html version eg. at
(2)
http://interglacial.com/javascript_spec/

The only figure in the whole standard is on page 3, and can be seen on this
page
(3)
http://interglacial.com/javascript_spec/a-4.html#a-4.2.1

In order to learn the standard I tried to write beautiful and intuitive
javascript code for the example, which is described in the figure in the
link(3) above.

I used the notations in the figure (CF, Cfp, cf1, cf2, cf3, cf4, cf5 and
their properties prototype, P1, CFP1, q1, q2).

The text description and the figure do not agree completely: the text
mentions property P2 of CF, but it is not in the figure. (can there be an
error in the standard!?)

Yesterday I tried hours(!) with firefox and its debugger firebug, and
checked with chrome. I tried numerous alternatives to define functions,
objects (are they the same?), and putting properties to them so that the
objects cf1 ... cf5 would have their expected properties in the end. Some of
the alternatives 'worked' and some did not, but I do not know yet exactly,
why. Just now the state of this project and my mind is total confusion :).

Objects and functions look very different in code, and intuitively I cannot
understand how they can be the same beasts, or are they? Eg.

function CF () {var P1='P1';this.q1='q1';this.q2='q2'}

var CFP = CFP1:'CFP1'}

var CF = function(){ };

var cf1 = new CF;


Firebug seemed to accept expressions new CF and new CF() happily. And that
after having learnt, that CF and CF() mean completely different things, and
not understanding the difference leads to difficult errors!

The order of executing statements, and where defining things seemed to lead
different results (cf3['CFP'] === ? )

It would be nice to try many correct ways to write code for the figure, AND
some intuitive but incorrect ways ... Also the explanations, why to write so
and why not. Yes I know these are partly matters of style, but too much
freedom is not good (why do the same thing in 7 different ways in one
project when 1 would suffice?).

Thoughts?
 
R

RobG

How to write code for an example in the ECMAScript standard?

ECMAScript Standard ECMA-262 , 3rd edition (December 1999) is available as
pdf-file (size 720 951 bytes) to download at
(1)http://www.ecma-international.org/publications/standards/Ecma-262.htm

and inofficial html version eg. at
(2)http://interglacial.com/javascript_spec/

The only figure in the whole standard is on page 3, and can be seen on this
page
(3)http://interglacial.com/javascript_spec/a-4.html#a-4.2.1

In order to learn the standard I tried to write beautiful and intuitive
javascript code for the example, which is described in the figure in the
link(3) above.

I used  the notations in the figure (CF, Cfp, cf1, cf2, cf3, cf4, cf5 and
their properties prototype, P1, CFP1, q1, q2).

The text description and the figure do not agree completely: the text
mentions property P2 of CF, but it is not in the figure. (can there be an
error in the standard!?)

There are a couple of errors in that diagram, you've noted one.

Yesterday I tried hours(!)  with firefox and its debugger firebug, and
checked with  chrome. I tried numerous alternatives to define functions,
objects (are they  the same?), and putting properties to them so that the
objects cf1 ... cf5 would have their expected properties in the end. Someof
the alternatives 'worked'  and some did not, but I do not know yet exactly,
why. Just now the state of this project and my mind is total confusion :)..

Objects and functions look very different in code, and intuitively I cannot
understand how they can be the same beasts, or are they? Eg.

function CF () {var P1='P1';this.q1='q1';this.q2='q2'}

You need to learn the difference between an object property and a
local variable of a function. Try this article by Richard Cornford,
it's about closures but goes into detail about variable instatiation

<URL: http://jibbering.com/faq/faq_notes/closures.html >

(the site seems to not be responding right now).

After creating the function object, create the properties:

function CF(){
this.q1='q1';
this.q2='q2';
}
CF.P1 = 'P1';
CF.P2 = 'P2';

var CFP = CFP1:'CFP1'}

There's a syntax error (missing brace), try:

var CFP = {CFP1: 'CFP1'};


You need to assign that object to the public prototype property of the
CF function object:

CF.prototype = CFP
var CF = function(){ };

Function and variable declarations are processed before any code is
executed. When this line is reached, the global CF property that to
this point was a reference to the CF function declared above, is now
assigned a reference to the empty anonymous function on the right hand
side (rhs).


var cf1 = new CF;

Firebug seemed to accept expressions new CF and new CF() happily. And that
after having learnt, that CF and CF() mean completely different things, and
not understanding the difference leads to difficult errors!

That is per the specification (11.2.2), functions do not require a
formal parameter list when using the new operator, but most (nearly
all) code I've seen uses an empty list rather than none (it just seems
better practice I think).

The order of executing statements, and  where defining things seemed tolead
different results (cf3['CFP'] === ? )

Function and variable declarations and processed before any code is
executed. Code is executed in the order it is encountered within its
execution context (see Richard's article).

It would be nice to try many correct ways to write code for the figure, AND
some intuitive but incorrect ways ... Also the explanations, why to writeso
and why not. Yes I know these are partly matters of style, but too much
freedom is not good  (why do the same thing in 7 different ways in one
project when 1 would suffice?).

Thoughts?

I don't think the specification is a good place for examples. A user
guide is the place for that, unfortunately there are very few of those
worth recommending, see the FAQ (I'd give you a link but it's dead
right now).

Here's an article I wrote about prototypes some time ago, I've not
published a link to it before as it requires some work (there is a
minor error in Fig 4 at least), please treat it as an unfinished
draft. Hopefully you find it useful and it doesn't lead you astray:

<URL: http://robgbne.wordpress.com/category/javascript/ >
 
A

abozhilov

How to write code for an example in the ECMAScript standard?
ECMAScript Standard ECMA-262 , 3rd edition (December 1999) is availableas
pdf-file (size 720 951 bytes) to download at
(1)http://www.ecma-international.org/publications/standards/Ecma-262.htm
and inofficial html version eg. at
(2)http://interglacial.com/javascript_spec/
The only figure in the whole standard is on page 3, and can be seen on this
page
(3)http://interglacial.com/javascript_spec/a-4.html#a-4.2.1
In order to learn the standard I tried to write beautiful and intuitive
javascript code for the example, which is described in the figure in the
link(3) above.
I used  the notations in the figure (CF, Cfp, cf1, cf2, cf3, cf4, cf5and
their properties prototype, P1, CFP1, q1, q2).
The text description and the figure do not agree completely: the text
mentions property P2 of CF, but it is not in the figure. (can there be an
error in the standard!?)

There are a couple of errors in that diagram, you've noted one.
Yesterday I tried hours(!)  with firefox and its debugger firebug, and
checked with  chrome. I tried numerous alternatives to define functions,
objects (are they  the same?), and putting properties to them so thatthe
objects cf1 ... cf5 would have their expected properties in the end. Some of
the alternatives 'worked'  and some did not, but I do not know yet exactly,
why. Just now the state of this project and my mind is total confusion :).
Objects and functions look very different in code, and intuitively I cannot
understand how they can be the same beasts, or are they? Eg.
function CF () {var P1='P1';this.q1='q1';this.q2='q2'}

You need to learn the difference between an object property and a
local variable of a function. Try this article by Richard Cornford,
it's about closures but goes into detail about variable instatiation

<URL:http://jibbering.com/faq/faq_notes/closures.html>

(the site seems to not be responding right now).

After creating the function object, create the properties:

  function CF(){
    this.q1='q1';
    this.q2='q2';
  }
  CF.P1 = 'P1';
  CF.P2 = 'P2';
var CFP = CFP1:'CFP1'}

There's a syntax error (missing brace), try:

  var CFP = {CFP1: 'CFP1'};

You need to assign that object to the public prototype property of the
CF function object:

  CF.prototype = CFP


var CF = function(){ };

Function and variable declarations are processed before any code is
executed. When this line is reached, the global CF property that to
this point was a reference to the CF function declared above, is now
assigned a reference to the empty anonymous function on the right hand
side (rhs).
var cf1 = new CF;
Firebug seemed to accept expressions new CF and new CF() happily. And that
after having learnt, that CF and CF() mean completely different things,and
not understanding the difference leads to difficult errors!

That is per the specification (11.2.2), functions do not require a
formal parameter list when using the new operator, but most (nearly
all) code I've seen uses an empty list rather than none (it just seems
better practice I think).
The order of executing statements, and  where defining things seemed to lead
different results (cf3['CFP'] === ? )

Function and variable declarations and processed before any code is
executed. Code is executed in the order it is encountered within its
execution context (see Richard's article).
It would be nice to try many correct ways to write code for the figure,AND
some intuitive but incorrect ways ... Also the explanations, why to write so
and why not. Yes I know these are partly matters of style, but too much
freedom is not good  (why do the same thing in 7 different ways in one
project when 1 would suffice?).
Thoughts?

I don't think the specification is a good place for examples. A user
guide is the place for that, unfortunately there are very few of those
worth recommending, see the FAQ (I'd give you a link but it's dead
right now).

Here's an article I wrote about prototypes some time ago, I've not
published a link to it before as it requires some work (there is a
minor error in Fig 4 at least), please treat it as an unfinished
draft. Hopefully you find it useful and it doesn't lead you astray:

<URL:http://robgbne.wordpress.com/category/javascript/>

Hi rob. This diagram
<URL: http://robgbne.files.wordpress.com/2008/06/diagrams_1.gif >
Little confused for my. Instance have property from constructor. This
members Ecma 3 calling "Properties of Object Instances". Such a every
member create from scope of constructor function. But not only from
constructor. Prototype object is static, he is same for everything
instance of Object. But if you have variable who's passing by value,
hes been copy for every instance of Object.
Simple example:

function Foo(){};
Foo.prototype.a = 10;
Foo.prototype.arr = [];

var bar = new Foo();
bar.a++;
alert(bar.a); //11 expect
alert(Foo.prototype.a); //10 expect
bar.arr.push('a', 'b', 'c');
alert(Foo.prototype.arr); // a, b, c arr is object who been passed by
reference

Anyway, if you want this arr property to creating every time, you need
to create this property in constructor scope. Logical. For me is
interesting, what is the value of this in prototype inheritance? I
thing, when we speaking about "Prototype", "this" is object, who copy
every member from prototype object. And constructor set new member of
this object they are "Object instance properties", and finally
constructor:

return this;

If any member in prototype is object, in this will been copy
reference, not copy from this object. Again logical in this case. If
every time copy object, we use much more memory, for object iunstance.

By the way, i think when i use "new" keyword initialize "this" object,
and change context of Constructor. If i call constructor without "new"
keyword, i don't initialize "this" object, and context of that
Function is Global Object.
I my post is wrong. Please excuse me. I want to know, how is right.
How it works "this" keyword when calling some Constructor with "new"
keyword.
Thanks.
 
A

abozhilov

function Foo()
{
}

new Foo();
//When calling with "new", create object who copy all member from
Foo.prototype and Foo.prototype and value of "this" is reference to
this created object.
//Adding new property in constructor and any method of Foo is
equivalent of:
var bar = new Foo(); //new Foo, return "this". "this" is pointer to
created object.
bar.new_prop = some_value;

That's i thing. If i wrong, please explain my how it works.

Another interesting but logical behavior is:

function Foo()
{
this.arr = [];
}

function Bar()
{
}
Bar.prototype = new Foo();

var a = new Bar();
a.arr.push('a', 'b', 'c');
alert(a.arr);
alert(Bar.prototype.arr);

var b = new Bar();
b.arr.push('d', 'e', 'f');
alert(b.arr);

Standard inheritance. Bar inherit from Foo. Set
Bar.prototype = new Foo(); //Getting member of Foo from Foo.prototype
and Foo member who's "Object instance properties" and pushed in
Bar.prototype. Regardless of arr is created from constructor of Foo he
again passed by reference and Bar.prototype is the same of any
instance from Bar. Every instance from bar works with same arr.
Logical again.

When i change Bar constructor function to:
function Bar()
{
Foo.call(this);
}
We change Foo context with "this", this time we have "arr" and all
properties who's "Object instance properties" like init in Foo. Again
logical.
But this is overhead by the way. When calling:

new Bar();

"this" is have this properties, and "Foo.call(this)", rewriting value
of this properties...

Doug's method to creating "prototypes" is much more clean. He don't
inherit from Constructor scope.

if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
function Foo()
{
}

new Foo();
//When calling with "new", create object who copy all member from
Foo.prototype and Foo.prototype and value of "this" is reference to
this created object.

Nothing is copied. Inheritance in these languages is facilitated by having
a prototype chain, a list of object( reference)s, that is traversed for the
name of the property being accessed; not by copying properties.

The /NewExpression/ results in a reference to an object that has a
`constructor' property that refers to the same object as `Foo', and the
object referred to by `Foo.prototype' is next in its prototype chain. (As
you do not assign that reference to anything here, the object created here
is immediately marked for garbage collection.)
//Adding new property in constructor and any method of Foo is
equivalent of:
var bar = new Foo(); //new Foo, return "this". "this" is pointer to
created object.

No. `new Foo()' results in a reference to a new object as described above.
That reference is assigned to `bar', so immediately after that assignment
is executed, `bar' refers to the new object. (Before execution takes place,
the Variable Object of the execution context is augmented with a `bar'
property that has the attribute `DontDelete', and that Variable Object is
put in front of the execution context's scope chain.)
bar.new_prop = some_value;

That's i thing. If i wrong, please explain my how it works.

The _ECMAScript Language Specification, Edition 3 Final_, is pretty clear
about how it works. Read it (bearing the errata in mind); do not just look
at the figures and infer from there.
Another interesting but logical behavior is:

function Foo()
{
this.arr = [];
}

function Bar()
{
}
Bar.prototype = new Foo();

var a = new Bar();
a.arr.push('a', 'b', 'c');
alert(a.arr);
alert(Bar.prototype.arr);

var b = new Bar();
b.arr.push('d', 'e', 'f');
alert(b.arr);

Standard inheritance.

What is "Standard inheritance"?
Bar inherit from Foo.

No. `Bar.prototype' would be a reference to a new object that has a
constructor property that refers to `Foo', and inherits from the object
referred to by `Foo.prototype'.
Set Bar.prototype = new Foo(); //Getting member of Foo from Foo.prototype
and Foo member who's "Object instance properties" and pushed in
Bar.prototype.

No. Your terminology is completely confused, and applied to the situation
incorrectly.
Regardless of arr is created from constructor of Foo he
again passed by reference

"passed by reference"? That is a term used for function/method arguments,
and it does not apply here; ECMAScript references are values (no pun intended).
and Bar.prototype is the same of any instance from Bar.
Every instance from bar works with same arr.
Correct.

Logical again.

But usually not what is wanted. Consider a stack implementation provided
by a constructor-prototype-pair, and two instances created with the
constructor. You would not want the instances to share their data, you
would want two different stacks. Therefore, the dummy object insertion
method described at the bottom of your posting.
When i change Bar constructor function to:
function Bar()
{
Foo.call(this);
}
We change Foo context with "this", this time we have "arr" and all
properties who's "Object instance properties" like init in Foo. Again
logical.
But this is overhead by the way. When calling:

new Bar();

"this" is have this properties, and "Foo.call(this)", rewriting value
of this properties...

I have no idea what that could mean, but it sounds wrong. Perhaps you would
be better understood if you provided a(n automated) translation into English
along with your native-language posting?
Doug's method to creating "prototypes" is much more clean. He don't
inherit from Constructor scope.

Both inheritance and `this' are unrelated to (lexical) scoping.
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}

That pattern, which is _not_ Douglas Crockfords invention, as far as I am
concerned, inserts a dummy object in the prototype chain so that the
resulting prototype chain is, in a nutshell:

... --> Object.create(o) === new F() --> o

It is necessary to emulate class-based inheritance in prototype-based
languages like these.

<http://en.wikipedia.org/wiki/Prototype-based_programming>


PointedEars
 
A

abozhilov

The /NewExpression/ results in a reference to an object that has a
`constructor' property that refers to the same object as `Foo', and the
object referred to by `Foo.prototype' is next in its prototype chain.  (As
you do not assign that reference to anything here, the object created here
is immediately marked for garbage collection.)

Oh my good. You are complete right. That's what i need.
When i write:

new Foo();
create new object with properties created from constructor, and this
object reference from "constructor" property to Foo.prototype?
Or maybe reference from internal property [[Prototype]] to
Foo.prototype?

If i have:
function Foo()
{
this.arr = [];
}
Foo.prototype.func = function(){};

var bar = new Foo();
bar.constructor = null;
alert(bar.func); // function(){};

Do
Nothing is copied.

Foo.prototype.a = 10;

var bar = new Foo();
bar.a++; //increment property a
alert(Foo.prototype.a); //still 10

How attach JavaScript this property "a" when i call: new Foo() to
created object?

I have no idea what that could mean, but it sounds wrong. Perhaps you would
be better understood if you provided a(n automated) translation into English
along with your native-language posting?

I want to say.
Foo.call(this);
When call parent constructor and change context to current object. He
reinitialize "arr" property. Every instance from Bar haves "arr" =
[];

So sorry for my dummy english. Please excuse my.
Sorry.
I will learn english soon, and i hope then my terminology is correct.
 
A

abozhilov

Nothing is copied.  Inheritance in these languages is facilitated by having
a prototype chain, a list of object( reference)s, that is traversed forthe
name of the property being accessed; not by copying properties.
The /NewExpression/ results in a reference to an object that has a
`constructor' property that refers to the same object as `Foo', and the
object referred to by `Foo.prototype' is next in its prototype chain.  (As
you do not assign that reference to anything here, the object created here
is immediately marked for garbage collection.)

Note to OP:

The resulting object will only have `constructor` property referencing
`Foo` object if another object is not explicitly returned from constructor.

function Foo(){ return { }; }
(new Foo).constructor === Foo; // false
(new Foo).constructor === Object; // true

[...]

Thanks again man.
Here is logical. You return new object in this case. Same like:

function Foo(){ return new Object();} //isn't return `this`.

returned object own `constructor` property to reference to `Object`.
This agree perfect.
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
[Thomas 'PointedEars' Lahn wrote:]
The /NewExpression/ results in a reference to an object that has a
`constructor' property that refers to the same object as `Foo', and the
object referred to by `Foo.prototype' is next in its prototype chain. (As
you do not assign that reference to anything here, the object created here
is immediately marked for garbage collection.)

Oh my good. You are complete right. That's what i need.
When i write:

new Foo();
create new object with properties created from constructor,

With properties created *through* the constructor *code*, so to speak.
and this object reference from "constructor" property to Foo.prototype?

No, see below.
Or maybe reference from internal property [[Prototype]] to
Foo.prototype?
Yes.

If i have:
function Foo()
{
this.arr = [];
}
Foo.prototype.func = function(){};

var bar = new Foo();
bar.constructor = null;
alert(bar.func); // function(){};

You can assign to an object's `constructor' property later; that does not
change the prototype chain of that object (which is why the "dummy object
insertion" pattern works even if the `F' constructor for the dummy object
is declared only once, for example per closure):

var inheritFrom = (function() {
function F() {}

return function(o) {
F.prototype = o;
return new F();
};
})();

Do what?
Foo.prototype.a = 10;

var bar = new Foo();
bar.a++; //increment property a
alert(Foo.prototype.a); //still 10

How attach JavaScript this property "a" when i call: new Foo() to
created object?

bar.a++;

is equivalent to

bar.a = bar.a + 1;

As the object referred to by `bar' does not have an property named `a'
before the assignment, that property is only found, through the prototype
chain, in its prototype object.

Before `bar.a++':

,-----------------. ,-----------------. ,------------------.
| bar¹ |--> | Foo.prototype |--> | Object.prototype |--> ...
|=================| |=================| |==================|
| | | a : number = 10 | | ... |
`-----------------' `-----------------' `------------------'

After `bar.a++':

,-----------------. ,-----------------. ,------------------.
| bar |--> | Foo.prototype |--> | Object.prototype |--> ...
|=================| |=================| |==================|
| a : number = 11 | | a : number = 10 | | ... |
`-----------------' `-----------------' `------------------'

¹ For brevity and clarity, I am using the names of the properties that
refer to objects to identify objects here. However, you should be aware
that objects have identity, not name; an object can be referred to by
more than one property (variables are properties of a Variable Object).
I have no idea what that could mean, but it sounds wrong. Perhaps you would
be better understood if you provided a(n automated) translation into English
along with your native-language posting?

I want to say.
Foo.call(this);
When call parent constructor and change context to current object. He
reinitialize "arr" property. Every instance from Bar haves "arr" =
[];

The term `context' is usually associated with `execution context', and in
that sense your statement is wrong.

The (execution) context is _not_ changed to the current object; the `this'
value of the called execution context is changed. And for that value, of
course, the `this' value of the calling execution context is used here.

As the `this' value of the calling execution context, because it is a
constructor context, refers to the object being constructed, that object is
augmented with an `arr' property. And every `[]' creates and initializes
another, new Array instance (without an elements list, it is equivalent to
`new Array').


Please keep an attribution line for each quotation level.

<http://jibbering.com/faq/#posting>


PointedEars
 
A

abozhilov

Thomas. Thank you so much. This is perfect explain. In every tutorial
who's, i reading, nothing explain like this.

Typo error. If you want

var reader = "DUMMY READER",
reader_understand = false;
do {
explainPrototypeChainInJavaScript(reader);
}while(!reader_understand)

This is joke.
  bar.a++;

is equivalent to

  bar.a = bar.a + 1;

As the object referred to by `bar' does not have an property named `a'
before the assignment, that property is only found, through the prototype
chain, in its prototype object.

Before `bar.a++':

  ,-----------------.    ,-----------------.    ,------------------.
  | bar¹            |--> | Foo.prototype   |--> | Object.prototype |--> ...
  |=================|    |=================|    |==================|
  |                 |    | a : number = 10 |    | ...              |
  `-----------------'    `-----------------'    `------------------'

After `bar.a++':

  ,-----------------.    ,-----------------.    ,------------------.
  | bar             |--> | Foo.prototype   |--> | Object.prototype |--> ...
  |=================|    |=================|    |==================|
  | a : number = 11 |    | a : number = 10 |    | ...              |
  `-----------------'    `-----------------'    `------------------'

¹  For brevity and clarity, I am using the names of the properties that
   refer to objects to identify objects here.  However, you should be aware
   that objects have identity, not name; an object can be referred toby
   more than one property (variables are properties of a Variable Object).

Excellent example. I have another question.

function Foo()
{
this.a = 10;
}
Foo.prototype.a = 20;

var bar = new Foo();
alert(bar.a);
delete bar.a;
alert(bar.a);

If i defined "a" in constructor and prototype chain. In this case when
i make:
var bar = new Foo();
"a" assigned directly in "bar"? After deleting, when i try to access
value of "a", JavaScript look first in object who assigned to "bar",
after that look in Foo.prototype and up on prototype chain. Sorry for
my English.
The term `context' is usually associated with `execution context', and in
that sense your statement is wrong.

The (execution) context is _not_ changed to the current object; the `this'
value of the called execution context is changed.  And for that value, of
course, the `this' value of the calling execution context is used here.

As the `this' value of the calling execution context, because it is a
constructor context, refers to the object being constructed, that object is
augmented with an `arr' property.  And every `[]' creates and initializes
another, new Array instance (without an elements list, it is equivalent to
`new Array').

Exactly that i want to say. Whatever, my english is very very bad.
 
T

Thomas 'PointedEars' Lahn

This is an attribution line. Please keep it when replying.
vvvvvvvvvvvvvvvv said:
Thomas. Thank you so much. This is perfect explain. In every tutorial
who's, i reading, nothing explain like this.

You are welcome. (Perhaps I should be writing JavaScript tutorials? ;-))
Typo error. If you want

var reader = "DUMMY READER",
reader_understand = false;
do {
explainPrototypeChainInJavaScript(reader);
}while(!reader_understand)

This is joke.

To make it perfect, you should write

var reader = {
name: "DUMMY READER",
understands: false,

read: function(s) {
/* left as an exercise */
}
};

do {
knowledgeable.explainPrototypeChainInJavaScript(reader);
} while (!reader.understands);

;-)
function Foo()
{
this.a = 10;
}
Foo.prototype.a = 20;

var bar = new Foo();
alert(bar.a);
delete bar.a;
alert(bar.a);

If i defined "a" in constructor and prototype chain. In this case when
i make:
var bar = new Foo();
"a" assigned directly in "bar"?

In the object referred to by `bar' later, yes.
After deleting, when i try to access value of "a", JavaScript look first
in object who assigned to "bar",

In the object referred to by `bar', more precisely by the object reference
that `bar' stores then.
after that look in Foo.prototype and up on prototype chain.

Correct. Because of the Prototype Chain lookup, a property defined for an
object's prototype or another object in that object's Prototype Chain can
serve as default value for the property of an object.


PointedEars
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top