473,805 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancelling instantiation

Other than throwing an exception during the execution of an object's
constructor, is there any way to cancel creation of the object in such a
way that it leaves a reference to it null or undefined. That would enable
the simple test:

var ref = new someObject();

if( ref ) {
// Object created successfully
}

I know one could use state flags instead, but the object I have in mind
shouldn't exist if the arguments passed to it are incorrect (there is a
good reason, trust me).

[OT - Exceptions in general (including other languages)]

Some people seem to have issues concerning throwing an exception during
object construction to signify failure and instead prefer to use state
flags. Any thoughts either way?

[/OT]

By the way, it's not possible to have protected[1] members in JavaScript,
is it? Shame...

Many thanks,
Mike
[1] I do mean protected, not private.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05
16 1369
On Tue, 02 Mar 2004 18:40:55 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
"Richard Cornford" <Ri*****@litote s.demon.co.uk> writes:
Richard Cornford wrote:
<snip>
... (I have got a copy of the 3nd edition of ECMA 262

^
That should have been 2nd edition.


I was about to say "me too", but found that it can be downloaded
at <URL:http://www.mozilla.org/js/language/> (along with version 1).


Thank you, both of you.

It's strange that the earlier editions aren't available from the ECMA
website, or that changes between versions aren't marked.

I do have the 3rd edition, but I can rarely make heads or tails of it. It
must be the worst written, yet grammatically-correct document I've ever
read. I find it odd that that level of incomprehensibi lity is acceptable
to the authors. I would have thought that the aim of the document would be
to explain the language to anyone who wishes to use it, as other language
specifications attempt to do. I'm not too sure who that document is geared
towards. It certainly isn't at a level that the casual script author can
use. Compare it to the Java Language Specification, for example.

Richard: Thank you for your explanation of protected members in
JavaScript, and for the comments on my proposed approach. I guessed that
there would be problems, but I didn't think that it would be with the
availability of instanceof (it was introduced in v1.4 with exceptions). I
won't be able to review the code you presented tonight, but I will
tomorrow.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #11
On Tue, 02 Mar 2004 12:55:33 -0500, Randy Webb <hi************ @aol.com>
wrote:
Richard Cornford wrote:
(I have got a copy of the 3nd edition of ECMA 262
which I could e-mail you if you are interested)


I am please.


You can obtain the 3rd Ed. directly from ECMA for free as a PDF:

http://www.ecma-international.org/pu...s/Ecma-262.htm

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #12
Michael Winter wrote:
On Tue, 02 Mar 2004 12:55:33 -0500, Randy Webb <hi************ @aol.com>
wrote:
Richard Cornford wrote:
(I have got a copy of the 3nd edition of ECMA 262
which I could e-mail you if you are interested)

I am please.

You can obtain the 3rd Ed. directly from ECMA for free as a PDF:

http://www.ecma-international.org/pu...s/Ecma-262.htm


Thanks Mike. I saw Lasse's post after I replied and have them both book
marked now :-)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 20 '05 #13
Michael Winter <M.******@bluey onder.co.invali d> writes:
I do have the 3rd edition, but I can rarely make heads or tails of
it. It must be the worst written, yet grammatically-correct document
I've ever read.
I have seen worse :)
I find it odd that that level of incomprehensibi lity
is acceptable to the authors. I would have thought that the aim of the
document would be to explain the language to anyone who wishes to use
it, as other language specifications attempt to do.
I disagree. The purpose of a language specification is to define the
language unambiguously and exactly. It is not a tutorial, it is a
reference document. Adding too much explanation text risks adding
ambiguiuity either in the text or between the text and the formal
specification.

Ofcourse, there should also be a tutorial, but I guess ECMA left that
to the Netscape and Microsoft Corporations or other implementors of
the language.
I'm not too sure who that document is geared towards. It certainly
isn't at a level that the casual script author can use. Compare it to the Java Language Specification, for example.


Ok, ECMAScript is not exactly easy to read :) I admit that the JLS
is easier to read, although it too can get pretty hard too.
Is it also as complete, including the behavior of all build-in
functions?

Now compare it to the R5RS
<URL:http://www.swiss.ai.mi t.edu/~jaffer/r5rs_toc.html>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #14
On Tue, 02 Mar 2004 19:29:48 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Michael Winter <M.******@bluey onder.co.invali d> writes:
I do have the 3rd edition, but I can rarely make heads or tails of
it. It must be the worst written, yet grammatically-correct document
I've ever read.
I have seen worse :)


I don't doubt that.
I find it odd that that level of incomprehensibi lity
is acceptable to the authors. I would have thought that the aim of the
document would be to explain the language to anyone who wishes to use
it, as other language specifications attempt to do.


I disagree. The purpose of a language specification is to define the
language unambiguously and exactly. It is not a tutorial, it is a
reference document. Adding too much explanation text risks adding
ambiguiuity either in the text or between the text and the formal
specification.


It would depend on who is the target audience. The Standard doesn't say,
but it does seem that, due to the detail in how methods are implemented,
writers of a JavaScript interpreter are the most likely.
Ofcourse, there should also be a tutorial, but I guess ECMA left that
to the Netscape and Microsoft Corporations or other implementors of
the language.
I don't find that the Netscape and Microsoft references are always
sufficient. For the most part, they are fine, but I would like something
between them and ECMA-262.
I'm not too sure who that document is geared towards. It certainly
isn't at a level that the casual script author can use.

Compare it to the Java Language Specification, for example.


Ok, ECMAScript is not exactly easy to read :) I admit that the JLS
is easier to read, although it too can get pretty hard too.
Is it also as complete, including the behavior of all build-in
functions?


I can't say for certain. It has been a year since I read it properly (I
went front-to-back then). However, if memory serves, the grammar of the
language is fully specified. Multi-threading issues are covered to a level
where a conforming implementation could be built. I think even the loading
of class files is covered.

Perhaps the difference between them is that Sun provide the run-time
engine for virtually every operating system, so no implementations need to
be made. That allows the specification to concentrate on language itself,
and not its internal behaviour. If ECMA-262 contained some additional
comments that summarise the processes described, it would be a good step
forward. This would allow both precision and comprehension.
Now compare it to the R5RS
<URL:http://www.swiss.ai.mi t.edu/~jaffer/r5rs_toc.html>


In what regard: specificity or ease of reading?

With the former, it appears to be about equal to JLS. Somewhat more
verbose, perhaps, but not radically different.

With the latter, I can't honestly say without reading and understanding a
good proportion of the text which I haven't had the time to do, and have
no inclination to do at this time of night :) Superficially, it is easier
to comprehend than ECMA-262.

The two major stumbling blocks I have are the indirect method of
description, and the choice of language. The specification seems to be
written with an incremental approach, where parts of an explanation rely
heavily on previous topics (the definition of some basic functions, for
example). This gives the impression that one must virtually memorise the
first few sections before even considering the use of the remaining
document, which makes it useless (for me) for a reference. The language is
a minor problem in comparison. To illustrate that, the only example I
could find after a quick search is the use of "Disjunctio n" instead of
"Separator" in the grammar for regular expression patterns.

Perhaps, at some point, I should read the whole thing slowly, rather than
to try and use it to understand certain elements of the language.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #15
This is incorrect, JS does not support protected members.

George Jempty <fl********@bel lsouth.net> wrote in message news:<mO******* **********@bign ews4.bellsouth. net>...
<snip>
By the way, it's not possible to have protected[1] members in
JavaScript, is it? Shame...


No, this is one of the great fallacies about Javascript. Javascript
supports closures and therefore supports protected/private members. See:

http://www.crockford.com/javascript/private.html

Jul 20 '05 #16
> This is incorrect, JS does not support protected members.

Java needs protected members to compensate for the brittleness of the
classical object model. JavaScript is class-free, and so does not need
them. See http://www.crockford.com/javascript/inheritance.html
Jul 20 '05 #17

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

Similar topics

1
1890
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. One of the main problems at this point lies in cancelling the event. I have found that the TAB fires the onkeypress in NN, but not in IE. I can cancel the onkeypress fine in NN. The TAB fires the onkeydown in IE and can be cancelled in IE. ...
7
1696
by: johny smith | last post by:
Based on my experience there is two ways to instantiate an object. Method 1: Car* car1 = new Car();
7
1710
by: Hunter Hou | last post by:
Hello, I'm trying one example of <<the C++ programming language>> Page 865 int f( int ); template< class T > T g( T t ) { return f( t ); } char c = g( 'a' ); ************ char f( char ); Stroustrup said **** line is wrong because alternative resolution of f( t )
12
2631
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in an embedded environment with multiple processors. I created a policy for classes, which, I had hoped, would automatically register the class with the appropriate factory: // In some header file... #include <cassert>
4
1993
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is working fine but when I try to instantiate an XmlSerializer object with: Dim xmls As New XmlSerializer(GetType(CLayerDefinition)) I get the following error:
13
1713
by: Jake Barnes | last post by:
I saw this sentence: "The last stage of variable instantiation is to create named properties of the Variable object that correspond with all the local variables declared within the function." here: http://jibbering.com/faq/faq_notes/closures.html
3
4009
by: Steven T. Hatton | last post by:
Has anybody here used explicit instantiation of templates? Has it worked well? Are there any issues to be aware of? -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
2
1882
by: WittyGuy | last post by:
Hi My class looks something like this: class Base { public: Base () {} ~Base () {} // No virtual dtor in the base class private: };
2
3685
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
4
2493
by: yuanhp_china | last post by:
I define a class in A.h: template <class Tclass A{ public: void get_elem( const T&) ; };
0
9718
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
9596
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
10613
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
10363
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
10368
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
10107
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
6876
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();...
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.