473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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.

Jan 25 '07 #1
3 1515
VK


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

Jan 25 '07 #2


On Jan 25, 4:29 pm, "gg9h0st" <mn9h...@hotmail.comwrote:
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.
--
Rob

Jan 25 '07 #3


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

Jan 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
41
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
17
by: Matt Kruse | last post by:
Perl's map() function is a powerful shortcut to accomplish many "loop over an array and do X" operations. Below is a quick hack to simulate similar functionality. I've used it a few times and find...
3
by: Jeff Stewart | last post by:
I've been working with the JavaScript Shell in Firefox on a mad-scientist problem I've had in my head. Assume a function named 'object' that is designed to create an object based on a prototype...
6
by: Cylix | last post by:
I just know the form like: myObject.prototype.linkFade = function(link, doShow) { .... .... .... }...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
18
by: Aaron Gray | last post by:
I know this has probably been argued to death, but I am going to raise it fresh again, and basically lets have an unofficial 'isArray()' contest that we can hopefully put it to rest as best as we...
7
by: Andrew Poulos | last post by:
Say I have this foo = function() { // blah }; bar = fuction(fnName) { /* If fnName equalled "foo" * How do I test that foo, as a function, * exists and then, if it exists, call it?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.