473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.r r = 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 1532
VK


On Jan 25, 9:29 am, "gg9h0st" <mn9h...@hotmai l.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.c om/group/comp.lang.javas cript/msg/34c45102bf9b5a8 c>,
also you may read the entire thread as well.

Jan 25 '07 #2


On Jan 25, 4:29 pm, "gg9h0st" <mn9h...@hotmai l.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.r r = 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...@hotmai l..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.r r = 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
15224
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 am doing wrong? Your help will be much appreciated. Thanks
41
2577
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 += arguments;
17
2021
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 it to be quite handy. Any thoughts? <script type="text/javascript"> function map(func) { var i,j,o; var results = ;
3
1402
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 object -- the semantic is that the returned object prototypally inherits from the argument 'o'. function object(initializer, o) { if (!o) o = Object; function f() {} f.prototype = o;
6
1417
by: Cylix | last post by:
I just know the form like: myObject.prototype.linkFade = function(link, doShow) { .... .... .... } ----------------------------------------------------------------------------------------------------------------------------------- myObject.prototype.linkFade = function(link, doShow) { with (this) { .... ....
28
4336
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
2242
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
1852
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 can. I have found things that work perfectly well as long as you don't try them on MSIE, ie adding Object and Array prototype isArray functions, thus :- Object.prototype.isArray = function() { return false } Array.prototype.isArray =...
7
1716
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
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.