I remember reading somewhere (I think it was in one of Crockford's papers) that using an array literal [] is better than using the new Array(); notation.
But I can't really remember any advantages of one over the other.
Can anyone please explain to me on why the former is preferred over the latter?
[Update]
Here is a reason on why []...
If I want some text to appear literally in a Django template, e.g.
{{Image.jpg|title}}
and I want that text to be output (not interpretated) in the HTML, how do I do so?
...
In a literal string (@"foo") in C#, backslashes aren't treated as escapes, so doing \" to get a double quote doesn't work. Is there any way to get a double quote in a literal string?
(This understandably doesn't work: string foo = @"this \"word\" is escaped";)
...
I tried to type char literals for accentuated vowels in Java, but the compilers says something like: unclosed character literal
This is what I'm trying to do:
char [] a = {'à', 'á', 'â', 'ä' };
I've tried using Unicode '\u00E0' but for some reason they don't match with my code:
for( char c : string.toCharArray() ) {
if( c == ...
A discussion earlier today led me to question whether or not my understanding of primtives and literals is correct.
My understanding is that a literal type is specifically a type which can have a value assigned using a notation that both human and compiler can understand without specific type declarations:
var firstName = "John"; // ...
For example:
// This will become either SomeMethodA or SomeMethodW,
// depending on whether _UNICODE is defined.
SomeMethod( _T( "My String Literal" ) );
// Becomes either AnotherMethodA or AnotherMethodW.
AnotherMethod( _TEXT( "My Text" ) );
I've seen both. _T seems to be for brevity and _TEXT for clarity. Is this merely a subjectiv...
Named lists in an excel sheet are referenced from another sheet on the same book.
E.g.
Sheet 2 has the named lists(GRPCNT) contain strings
> 5
5 - 9
10 - 20
> 20
Sheet 1 uses GRPCNT to provide a list of options.
Say, there are three rows
A | > 5
B | > 20
C | > 5
Sheet 1 has to determine the number of occurrences of each option f...
I'm working on an embedded project and I'm trying add more structure to some of the code, which use macros to optimize access to registers for USARTs. I'd like to organize preprocessor #define'd register addresses into const structures. If I define the structs as compound literals in a macro and pass them to inline'd functions, gcc has...
Possible Duplicate:
What’s the difference between Array() and [] while declaring a JavaScript array?
In JavaScript you can create a new array like:
var arr = new Array();
or like:
var arr2 = [];
What is the difference and why would you do one over the other?
...
I have got a literal control on page (with some data on it). i want to access it in javascript and want to put some text on it. please tell me how can i access literal control in javascript. (i am using asp.net)
My code in javascript (but not working):
lths = document.getElementById("<%= lblhs.ClientID %>");
lths.innerHTML = 'this i...
Hi
Can anyone explain why example 1 below works, when the r prefix is not used?
I thought the r prefix must be used whenever escape sequences are used?
Example 2 and example 3 demonstrates this..
# example 1
import re
print (re.sub('\s+', ' ', 'hello there there'))
# prints 'hello there there' - not expected as r prefix is not...
I am building a small gallery that will only have 20 or so images in it. I'd like to have this data stored somewhere (even in the PHP file itself) and so am looking at ways of encoding the data as a literal or resource file.
In JavaScript, I would use notation resembling (from memory):
var albums = [
{ name='Album 1', photos=['photo...
I am trying to implement an eqivilent version of perl's chomp() function in C and I have come across a corner case where a string literal passed as the argument will cause a segmentation fault (rightfully so).
Example chomp("some literal string\n");
Is there a defined way in C99 to detect wether or not my function was passed a string ...
In Java, I can't take a byte array of unsigned bytes (from something such as Wire Shark) and put this into java.... Because I will get compile errors since anything greater than 127 decimal/0x07F is treated not as a byte, but as an int.... IE:
byte[] protocol = { 0x04, 0x01, 0x00, 0x50, /*error*/0xc1, /*error*/0xdb, 0x1c, /*erro...
We are currently having an issue due to implicit conversion in an IF statement in VBScript (Classic ASP) that don't do implicit conversion the same way when dealing with a variable or a literal. Can someone explain this behavior to me, why do VBScript acts this way ?
Here is a sample of what I mean :
Const c_test = 3
Dim iId : iId = 3
...
Typically, I've seen people use the class literal like this:
Class<Foo> cls = Foo.class;
But what if the type is generic, e.g. List? This works fine, but has a warning since List should be parameterized:
Class<List> cls = List.class
So why not add a <?>? Well, this causes a type mismatch error:
Class<List<?>> cls = List.class
I ...
As in this code:
int nx = (int)((rev3[gx]) / 193U);
Whats with the U in the end of 193 ?
...
This very simple code:
#include <iostream>
using namespace std;
void exec(char* option)
{
cout << "option is " << option << endl;
if (option == "foo")
cout << "option foo";
else if (option == "bar")
cout << "opzion bar";
else
cout << "???";
cout << endl;
}
int main()
{
char opt[] = "foo...
Hi, I am always confused about return a string literal or a string from a function. I was told that there might be memory leak because you don't know when the memory will be deleted?
For example, in the code below, how to implement foo() so as to make the output of the code is "Hello World"?
void foo ( ) // you can a...
Hello everyone :)
I've got a bit of a problem. Essentially, I need to store a large list of whitelisted entries inside my program, and I'd like to include such a list directly -- I don't want to have to distribute other libraries and such, and I don't want to embed the strings into a Win32 resource, for a bunch of reasons I don't want t...