Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old January 25th, 2007, 06:35 AM
gg9h0st
Guest
 
Posts: n/a
Default function object and prototype.

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
Default 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
Default 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
Default 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 :)

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.