thanks peter,
you were absolutely correct, when we use constructor's to create
objects the constructor's prototype's properties are maintained by an
inbuilt [[prototype]] link and not accessible through object.prototype

while referring to the problem code

___________________________________________________

var Constructor = function(){};
Constructor.prototype.hello = "hello"
Constructor.prototype.value = 1;
Constructor.prototype.test = function() { console.log(this.hello); };

// creating object from this constructor class

var rj = new Constructor();    // create an instance of A

rj.test();
____________________________________________________

after reading some concept of internal [[prototype]] property , I was
able to access the properties of "rj"

to access the properties, we can use any of the three methods

console.log(rj.constructor.prototype);
console.log(Object.getPrototypeOf(rj));
console.log(rj.__proto__);

all returns the same output

{ hello: 'hello', value: 1, test: [Function] }
{ hello: 'hello', value: 1, test: [Function] }
{ hello: 'hello', value: 1, test: [Function] }

_____________________________________________________

On Wed, Jun 15, 2011 at 10:58 AM, Peter Lobsinger <[email protected]> wrote:
> On Tue, Jun 14, 2011 at 8:57 AM, rohit jangid <[email protected]> wrote:
>> thanks lucian.
>>
>> My view on inheritance was that.
>> 1) first an empty object is created and it prototype points to
>> constructor's prototype .
>> 2) this object is passed into the constructor function where it can be
>> refrenced by "this"
>> 3) this is returned when we use new operator with constructor funtion .
>>
>> but as I tried to print what is stored in rj and rj.prototype , rj was
>> empty object and rj.prototype was undefined. So how is it able to
>> access that test() property .
>
> I think what you are missing is that object [[prototype]] (notation
> used by ECMA-262 for internal properties) references are *implicit*
> links to their constructor's (explicitly referenced) prototype
> property. This means that rj.prototype need not bear any relation to
> the [[prototype]] of rj as used for inheritance purposes. IIUC, there
> is no mechanism in the standard to look up an object's [[prototype]]
> from user code (although some implementations provide extensions to do
> this).
>
> The core idea of this is documented in ECMA-262v3 section 4.2.1
> ("Objects") complete with a nice diagram. It can be obtained at
> http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm.
>
>> the problem came when , an object was using different properties and I
>> couldn't figured out how it was accessing them and what are the other
>> available properties.
>> _______________________________________________
>> http://lists.parrot.org/mailman/listinfo/parrot-dev
>>
>



-- 
Rohit Jangid
Under Graduate Student,
Deptt. of Computer Engineering
NSIT, Delhi University, India
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev

Reply via email to