473,804 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there any difference between Array() and new Array()

Hi All,

I have defined a function
function fct(arr) { ... }

When I call this function, I prefer to write
fct(Array(item1 , item2));

But if I write
fct(new Array(item1, item2));
The code above works as well. But Will it cause any memory leaks?
--
best regards
Xu, Qian (stanleyxu)
Mar 15 '08 #1
2 1743
On Mar 15, 8:55 am, "Xu, Qian" <no_re...@micro soft.comwrote:
Hi All,

I have defined a function
function fct(arr) { ... }

When I call this function, I prefer to write
fct(Array(item1 , item2));

But if I write
fct(new Array(item1, item2));
The code above works as well. But Will it cause any memory leaks?
--------------

<URL: http://www.ecma-international.o rg/publications/standards/Ecma-262.htm>

15.4.1 The Array Constructor Called as a Function
When Array is called as a function rather than as a constructor, it
creates and initialises a new Array
object. Thus the function call Array(...) is equivalent to the object
creation expression
new Array(...) with the same arguments.

--------------

Of course, you need to test the implementations to see if they
conform. I would guess "new Array()" is safer than "Array()".

The advantage of "new Array()" looks the same as your own JavaScript
constructors "new MyConstructor() "

Peter
Mar 15 '08 #2
On Mar 16, 1:55*am, "Xu, Qian" <no_re...@micro soft.comwrote:
Hi All,

I have defined a function
* *function fct(arr) { ... }

When I call this function, I prefer to write
* *fct(Array(item 1, item2));

But if I write
* *fct(new Array(item1, item2));
The code above works as well.
Further to what Peter wrote, you could also use an array literal:

fct([item1, item2]);
--
Rob
Mar 16 '08 #3

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

Similar topics

11
5724
by: Shea Martin | last post by:
I have been programming in C++ for over 4 years. I *think* I knew that a struct could have a constructor but I decided to dig into it a little more today, and found that there is very little difference between a struct and a class in C++. Both have inheritance, access modifiers, etc. The only diff I see is the default access level is public vs. private. I have always just used structs as a minimal class, as that is the way
10
5145
by: David | last post by:
what's the differences between: int main(int argc,char* argv){ ... } and: int main(int argc,char** argv){ ...
15
2248
by: Mohanasundaram | last post by:
Hi All, What is the difference between malloc and calloc other than the point that calloc will initialize the memory to all zeros? This was an interview question for me. All the books and references that I have come across tells that calloc initialize the memory to all zeros. In Herbert Shiltd's C/C++ reference I found that calloc returns a pointer to an array. I want to understand in what way the memory returned by malloc and calloc...
18
2273
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
7
3455
by: iamchiaweilin | last post by:
Hello all: What's the difference between p and q in the following statements? char p = "Hello"; char *q = "Hello"; I know q stores the address of 'H'. Question is: does p store the address of 'H' too?
33
2283
by: onkar | last post by:
#include<stdio.h> int main(int argc,char **argv){ int a={1,2,3,4,5}; printf("%p\n%p\n",a,&a); return 0; } gives me : 0xbfe837a0
5
4578
by: rajm2019 | last post by:
hi all, i want to know that what is the actual difference b/w the character array & character pointer.then how u will get the addrees of a char array char str="be silent like u" char *p1="be eloquent r u" char *p2; p2=str;
45
7401
by: anto frank | last post by:
hi friends, is ther any difference in array in c and array in c++?
10
3447
by: Ahmad Humayun | last post by:
Whats the difference between: char str1 = "wxyz"; char* str2 = "abcd"; I can do this: str2 = str1 but I can't do this: str1 = str2
11
12130
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my code is just returning me an array of 0's
0
9591
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
10594
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...
1
10331
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,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
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
5529
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
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.