function object and prototype.

G

gg9h0st

function aa() {};
var bb = new aa();

var dd = new function cc() {};

aa.prototype.rr = 100;
cc.prototype.rr = 100;

---------------------------------------------------------------

i wrote the code above that makes two functions and two object for
those.

bb(object)->aa(function),
dd(object)->cc(function).

i think it's all the same way to make an object for a function.

but if u try to debug,

bb object has rr right after "aa.prototype.rr = 100" statement
but dd deosn't have rr variable.

isn't dd obj refer to cc?

can anyone explain it why?

thanks in advance.
 
V

VK

function aa() {};
var bb = new aa();

var dd = new function cc() {};

aa.prototype.rr = 100;
cc.prototype.rr = 100;

---------------------------------------------------------------

i wrote the code above that makes two functions and two object for
those.

bb(object)->aa(function),
dd(object)->cc(function).

i think it's all the same way to make an object for a function.

No it is not. The second way is a rarely fustified trick (sometimes for
funny singletons maybe) - for the time being just pretend it doesn't
exist and use the conventional JavaScript object model.

More details can be found at
<http://groups.google.com/group/comp.lang.javascript/msg/34c45102bf9b5a8c>,
also you may read the entire thread as well.
 
R

RobG

function aa() {};
var bb = new aa();

var dd = new function cc() {};

Safari throws a parse error here and script execution stops.

aa.prototype.rr = 100;
cc.prototype.rr = 100;

If browsers get past where Safari errors, they will throw one at this
point: window.cc is not defined, attempting to access its prototype
property is doomed to failure.

The reference provided by VK is a good one.

i wrote the code above that makes two functions and two object for
those.

bb(object)->aa(function),
dd(object)->cc(function).

i think it's all the same way to make an object for a function.

It isn't.

but if u try to debug,

bb object has rr right after "aa.prototype.rr = 100" statement
but dd deosn't have rr variable.

Because an rr property was never added to dd or any object in its scope
chain.
isn't dd obj refer to cc?

dd refers to a function object constructed using the anonymous object
passed to the new operator (except in Safari :) ). The anonymous
function named cc has probably already ceased to exist.
 
G

gg9h0st

function aa() {};
var bb = new aa();

var dd = new function cc() {};

aa.prototype.rr = 100;
cc.prototype.rr = 100;

---------------------------------------------------------------

i wrote the code above that makes two functions and two object for
those.

bb(object)->aa(function),
dd(object)->cc(function).

i think it's all the same way to make an object for a function.

but if u try to debug,

bb object has rr right after "aa.prototype.rr = 100" statement
but dd deosn't have rr variable.

isn't dd obj refer to cc?

can anyone explain it why?

thanks in advance.

thanks VK and RobG.

the reference is greate one for me :)
 

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,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top