Connecting Tech Pros Worldwide Help | Site Map

function object and prototype.

  #1  
Old January 25th, 2007, 06:35 AM
gg9h0st
Guest
 
Posts: n/a
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.

  #2  
Old January 25th, 2007, 11:45 AM
VK
Guest
 
Posts: n/a

re: function object and prototype.




On Jan 25, 9:29 am, "gg9h0st" <mn9h...@hotmail.comwrote:
Quote:
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.

  #3  
Old January 25th, 2007, 12:15 PM
RobG
Guest
 
Posts: n/a

re: function object and prototype.




On Jan 25, 4:29 pm, "gg9h0st" <mn9h...@hotmail.comwrote:
Quote:
function aa() {};
var bb = new aa();
>
var dd = new function cc() {};
Safari throws a parse error here and script execution stops.

Quote:
>
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.

Quote:
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.

Quote:
>
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.
Quote:
>
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.


--
Rob

  #4  
Old January 26th, 2007, 06:45 AM
gg9h0st
Guest
 
Posts: n/a

re: function object and prototype.




On 1¿ù25ÀÏ, ¿ÀÈÄ3½Ã29ºÐ, "gg9h0st" <mn9h...@hotmail..comwrote:
Quote:
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 :)

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it not well to extend Object.prototype derictly? jidixuelang@gmail.com answers 2 August 12th, 2007 07:45 PM
JSON modifies Object.prototype? Kevin Newman answers 2 May 2nd, 2006 10:35 PM
Object.prototype, getters and setters Wei Wang answers 2 July 23rd, 2005 08:49 PM
arguments-object prototype Florian Loitsch answers 7 July 23rd, 2005 07:28 PM