473,703 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function and arguments as aguments

Hi. I have the following code:

function Tunnel() {

function Sum() {
var sum = 0;
for (i=0; i<arguments.len gth; i++) sum += arguments[i];

// calling Sum directly

// calling Sum through Tunnel
Tunnel(Sum, 1,2,3,4);

How should the Tunnel function be defined, knowing that the number of
parameters passed are unknown?

Feb 15 '06
41 2568
VK wrote:
function init() {
var out = document.getEle mentById('p1');

alert(arguments .constructor.pr ototype.isProto typeOf(Object.c onstructor.prot otype));
Yields true. Because:

arguments.const ructor.prototyp e.isPrototypeOf (
Object.construc tor.prototype)

| 10.1.8 Arguments Object
| [...]
| * The value of the internal [[Prototype]] property of the arguments object
| is the original Object prototype object, the one that is the initial
| value of Object.prototyp e (section

It is implied that arguments.const ructor is Object().

=== Object.prototyp e.isPrototypeOf (Object.constru ctor.prototype)

Because Object() is a (constructor) function, its constructor property is

=== Object.prototyp e.isPrototypeOf (Function.proto type)

And because of

| Object.prototyp e.isPrototypeOf (V)
| When the isPrototypeOf method is called with argument V, the following
| steps are taken:
| 1. Let O be this object.

O := Object.prototyp e;

| 2. If V is not an object, return false.

V = Function.protot ype is an object, nothing done.

| 3. Let V be the value of the [[Prototype]] property of V.

| 15.3.4 Properties of the Function Prototype Object
| [...]
| The value of the internal [[Prototype]] property of the
| Function prototype object is the Object prototype object
| (section

V := Function.protot ype.[[Prototype]] = Object.prototyp e

| 4. If O and V refer to the same object or if they refer to objects joined
| to each other (section 13.1.2), return true.

O === V, return true.
alert(arguments .constructor.pr ototype.isProto typeOf(Function .constructor.pr ototype));
Yields true, because of

arguments.const ructor.prototyp e.isPrototypeOf (
Function.constr uctor.prototype )

=== Object.prototyp e.isPrototypeOf (Function.proto type)
=== true

alert(arguments .constructor.pr ototype.isProto typeOf(String.c onstructor.prot otype));

Yields true, because of

arguments.const ructor.prototyp e.isPrototypeOf (
String.construc tor.prototype)

=== Object.prototyp e.isPrototypeOf (Function.proto type)
=== true
// use as argument anything else you want


window.onload = init;

The dark secret of JavaScript (which you should keep in secret :-) is
that at the very bottom of everything it's the same class constructor
based language as any others. [...]

Feb 20 '06 #41
VK wrote:
The dark secret of JavaScript (which you should keep in
secret :-) ...


You have made it clear that you 'program' on the basis of mystical
incantation and voodoo; fabricating you own complex web of
'explanations' for the phenomenon you mis-observe and chanting bizarre
sequences of operators, function calls and statements to you computer in
the hope that it will do something resembling what you want, but without
any ability to explain why you are using them.

This subject is not magic, there are no secrets (dark or otherwise),
just mechanism; pure deterministic mechanical logic. Seeing yourself as
the priest of some esoteric lore and sole knower or the ultimate truth
will only get in the way of your understanding of javascript. After all,
you claim to have been using javascript since the late 1990s, probably
longer than the majority of the regular contributors to this group, and
yet you understand less than people who have only been doing this for
just a couple of years. And you constantly see (but cannot express)
arcane significance in features that are no more than the direct
consequence of the specified mechanism.

Feb 20 '06 #42

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

Similar topics

by: Sabyasachi Basu | last post by:
While trying to port some stuff from Unix to Windows, I encountered a strange behaviour of function macros with empty arguments. Here is a small snippet which illustrates the problem: #include <iostream> #include <string> using namespace std; #define B(X, Y) Y
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
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...
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...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
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();...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.