473,788 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new Foo(); as a statement? (ECMAScript spec question)

Hi,

I am reading the ECMAScript specs trying to figure out if the next
line is a legal statement or not

new Foo();

I think the above code may only be legal as an expression and not as a
stand alone statement. Would this make the above a bug?

Douglas Crockford's JSLint will choke on the above line of code and
stop parsing. All the browsers seem to accept it as ok and work as I
expect: the returned object just doesn't get assigned to anything.

The time I have used a line like the above is when the constructor has
side effects and the "class" keeps track of all its instances.

Any ideas what is right or wrong in this case?

Thanks,
Peter

May 12 '07 #1
2 1271
On May 13, 6:05 am, Peter Michaux <petermich...@g mail.comwrote:
Hi,

I am reading the ECMAScript specs trying to figure out if the next
line is a legal statement or not

new Foo();

I think the above code may only be legal as an expression and not as a
stand alone statement. Would this make the above a bug?
I can't see the point in agonising over the difference between an
expression and a statement - it's moot.

e.g. who cares whether the following is an exression or a statement?

foo && foo();

Douglas Crockford's JSLint will choke on the above line of code and
stop parsing. All the browsers seem to accept it as ok and work as I
expect: the returned object just doesn't get assigned to anything.
JSLint is a *verifier*, not just a validator, so it looks for errors
beyond straight language validity to where it thinks you might have
made an error.

The time I have used a line like the above is when the constructor has
side effects and the "class" keeps track of all its instances.

Any ideas what is right or wrong in this case?
Seems OK to me, but I'd question why you are using a constructor this
way - there are usually many ways to achieve the same result. "Right"
or "wrong" can only really be judged in context, "better" or "best"
could be more appropriate terms.
--
Rob.

May 13 '07 #2
On May 12, 1:05 pm, Peter Michaux <petermich...@g mail.comwrote:
Hi,

I am reading the ECMAScript specs trying to figure out if the next
line is a legal statement or not

new Foo();

I think the above code may only be legal as an expression and not as a
stand alone statement. Would this make the above a bug?
<...>
>
Any ideas what is right or wrong in this case?
ECMA-262/3 12.4 should help with the answer.

--
.../rh

May 13 '07 #3

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

Similar topics

12
2322
by: Simula | last post by:
Hello All, Does anyone have any knowledge of when version 4 will be released? I think that version 3 was finalized in 1999 and it would be really nice to have the class keyword and statically typed variables. Thanks, Mark
35
3626
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is to management theses :-((( I must to declare and use all variable with this scheme :
13
2575
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
14
1649
by: António Marques | last post by:
Hi! I don't think I've ever been here, so I assume I'm addressing a bunch of nice people. Can you help me? I don't think there's a solution, but who knows. The thing is, picture a large project where you want some encapsulation. But a lot of it being grouping of what would otherwise be static members of the global namespace. So that instead of
6
3634
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but it gave a syntax error ("Invalid syntax") with caret pointing to the 'd' of the def keyword.
23
2076
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;'));
1
995
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - What does the future hold for ECMAScript? ----------------------------------------------------------------------- The ECMAScript Technical Committee is now working on the fourth edition, the first implementation of which is JScript.NET. It includes a compiler, allowing you to create standalone JScript executables. The fourth edition of ECMAScript will...
34
3016
by: dhtml | last post by:
I made a change to the FAQ of javascript to EcmaScript. I got some feedback that the newsgroup is CLJ and the language is commonly referred to as JavaScript. Therefore, the word in the FAQ should be JavaScript. So I'm asking: what should I use in the FAQ? Technically, 'JavaScript' is Mozilla's implementation of Ecma-262.
4
1774
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - What is ECMAScript? ----------------------------------------------------------------------- ECMAScript is the international standard for JavaScript. JScript 3.0 and JavaScript 1.5 are more or less ECMAScript compliant. In addition ECMA 327 defines the Compact Profile of ECMAScript by describing the features from ECMA 262 that may be omitted in some...
0
9498
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
10364
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
10172
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...
1
10110
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
6750
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
5398
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...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.